Monday, May 24, 2010

Error in c++ program?

I'm trying to find the max of 10 numbers and I don't need to keep the number after I've checked to see if it is greater then the max. I'm going off the model my teacher gave me but it's not working and nothing I do helps.





int max=0;


int n1;


int i=0;


while(i %26lt; 10)


{


cout%26lt;%26lt;"Enter number"%26lt;%26lt;endl;


cin%26gt;%26gt;n1;


if (max%26lt;n1)


max=n1


i=i+1


}


cout%26lt;%26lt;"The maximum number is"%26lt;%26lt;max%26lt;%26lt;endl;





when I check I come up with


error: expected unqualified-id before awhilea


error: expected constructor, destructor, or type conversation before a%26lt;%26lt;a token

Error in c++ program?
You need to declare a main() function as an entry point, so the program knows where to start. ^_^





#include %26lt;iostream.h%26gt;


int main()


{


(your above code goes here)


}
Reply:int max=0;


int n1;


int i=0;


while(i %26lt; 10)


{


cout%26lt;%26lt;"Enter number"%26lt;%26lt;endl;


cin %26gt;%26gt; n1;


if (max %26lt; n1)


max = n1;


i=i+1;


}


cout %26lt;%26lt; "The maximum number is" %26lt;%26lt; max %26lt;%26lt;endl;





You had missed two ;


No comments:

Post a Comment