424,972 Members | 901 Online Need help? Post your question and get tips & solutions from a community of 424,972 IT Pros & Developers. It's quick & easy.

Malformed if statements and program flow help

 P: 8 the idea here is to eliminate all solutions except for the square. I am stuck in trying to figure out how to utilize the if statement in the choice. I know its probably simple but its driving me crazy. any sugestins on how to make this better would be appreciated be specific do i need to remove something or add thank you Expand|Select|Wrap|Line Numbers #include  #include    using namespace std;   const int SQUARE = 1; const int TRIANGLE = 2; const int RECTANGLE = 3; const int CIRCLE = 4;   int main() {       // Declare Variable       int multiply;     int number5;     int number6;       // Declare Choice       int choice;         // Display Choice           cout << " What is the area of a square, triangle, rectangle, or circle? " ;         cout << " Make your choice? /n " ;                 cout << SQUARE << " ) Square: /n " ;         cout << TRIANGLE << " ) Triangle: /n " ;         cout << RECTANGLE << " ) Rectangle: /n " ;         cout << CIRCLE << " ) Circle: /n "  ;           // Get users choice           cin  >> choice ;       // Display Proper feedback based on users choice                       if (choice == TRIANGLE ) RECTANGLE ; CIRCLE; {               cout << " Choose another: /n" ;           }               if ( choice == SQUARE ) ;{            cout << "The area of a square is: /n" ;            }       // Get one side                 cout << " Enter one side: /n ";                 cin >> number5;       // Get the other side                 cout << " Enter other side: /n";                 cin >> number6;       // Multiply one side by the other                 multiply = number5 * number6 ;       // Display sum               cout <<  "Mulitply is " << multiply << endl;     system ("pause");       return 0;     } Sep 18 '10 #1
5 Replies

 Expert Mod 5K+ P: 8,916 if (choice == TRIANGLE ) RECTANGLE ; CIRCLE; { is mal formed, you need to check choice individually against each value you are interested in using the logical operators (&& ||) etc for example Expand|Select|Wrap|Line Numbers int a;   cin >> a;   if (a == 4 || a == 8) {     cout << "a is either 4 or 8) << endl; }   On line 48 you have a ; which will stop the if statement doing what you want. I think lines 52 - 65 should be inside the code block for the if ( choice == SQUARE ) condition. Sep 18 '10 #2

 P: 8 ok I dont get how to do exactly what you mean when i try to set it up that way it has run errors so I am still missing something here Sep 18 '10 #3

 100+ P: 542 Expand|Select|Wrap|Line Numbers if(choice=TRIANGLE||choice=RECTANGLE||... )choice=SQUARE; Maybe enum shape = {SQUARE,TRIANGLE......};//might be neater Sep 19 '10 #4

 P: 8 anymore suggestions here really could use some help Sep 20 '10 #5

 Expert Mod 5K+ P: 8,916 Err no other than writing you if statement the correct way you are unlikely to get further suggestions. Perhaps you should post the corrected code and the run time errors you are getting. Sep 20 '10 #6 