Saturday, May 22, 2010

I got a C++ problem. This program does not compile?

int main ()


{


do{


cout %26lt;%26lt; "Enter a choice number\n";


int choice;


cin %26gt;%26gt; choice;


switch(choice){


case 1: cout %26lt;%26lt; "(1) Area of circle\n";


break;


case 2 : cout %26lt;%26lt; "(2)Area of triangle\n";


break;


case 3 : cout %26lt;%26lt; "(3) Area of rectangle\n";


break;


case 4 : cout %26lt;%26lt;"(4) Quit\n";


break;}


while(choice!=4);


return 0;


//Somehow my "choice" at the end of the while loop is not recognised. The program loops when 1,2,3 is pressed and terminates when 4 is pressed.

I got a C++ problem. This program does not compile?
You should have a close parenthesis '}' after return 0;





Maybe you didn't copy and paste it here.


After case 4, I'd suggest adding "default:" for handling invalid values.





You also need to add a close parenthesis '}' before the while(choice!=4);





The one that's currently there closes out your switch statement, not your do-while loop.





You also aren't really presenting a menu. You're prompting for an imput then showing what the input means only after they've selected it. If you're trying to show a menu, you should have all your cout statements for each selection appear above the cout statement that prompts for the input. That way, when the program runs, the user will see all the options and be prompted for an input.
Reply:You need to close out the "do" statement and the function "main". Check out how many "{" characters you have versus how many "}". They should be the same (unless you're using those characters in a string)





BTW, are you trying to show a menu to the user? Because that's not what the program does.
Reply:May be you can post your requirements at http://expert.gionram.com/


and let many programmers bid for your project.


You can hire whoever you like.





Do not pay any money afront however.


No comments:

Post a Comment