Sunday, August 2, 2009

C++ problem?

i have to write a program that counts how many negative numbers the user enters. here is what i have so far:





void main()


{


cout %26lt;%26lt; "This program count how many negative numbers you enter. \nThere will be three sections. \nEnter 0 to end a section." %26lt;%26lt;endl%26lt;%26lt;endl;





for (int i=0; i%26lt;3; i++)


{


cout %26lt;%26lt; "\n************ SECTION " %26lt;%26lt; i+1 %26lt;%26lt; "**************"%26lt;%26lt;endl;


cout %26lt;%26lt; "\nYou have entered " %26lt;%26lt; getInput() %26lt;%26lt; " negative numbers so far."%26lt;%26lt;endl;


cout %26lt;%26lt; "**************************"%26lt;%26lt;endl%26lt;%26lt;endl...





}





return;


}





int getInput()


{


double number; //hold number entered by the user


count=0;





//get input


do


{


cout %26lt;%26lt; "Enter a number: ";


cin %26gt;%26gt; number;





//count positive number


if (number %26lt; 0)


count ++;


} while (number !=0);





//return counting result


return count;





}





when i compile it, it says "getInput" indentifier not found and count not declared. i dun see what i'm doing wrong. thanks for the help

C++ problem?
May be you can post your requirements at http://expert.ccietutorial.com/


and let many programmers bid for your project.


You can hire whoever you like.





Do not pay any money afront however.
Reply:As the previous responder said, you need to declare your variable count in the getInput( ) function, i.e. :


int count = 0;





The other problem is you're calling getInput( ) from main( ), but getInput( ) hasn't been declared or defined yet. The definition of the function appears below main( ) in your code, which is fine, but you need to declare it before it's called. So, you need this line before the beginning of main( ):





int getInput(void);





One other minor thing: the comment in getInput( ) says you're counting positive numbers, but you're counting negatives.
Reply:Try :


int count = 0;


not


count=0;


No comments:

Post a Comment