statements to make choices

Hi,

I am working on a program that will allow the user to make a choice. The program is based on the principles of finding the area of a Rectangle, Circle and Triangle. I want give the user a choice, for example:

A. Area of a Rectangle
B. Area of a Circle
C. Area of a Triangle

cout <<"Enter a letter: ";

cin >> letter;

cout <<"The area of a rectangle is: ";

Now, my question is do I need to define individual variable for A, B, & C, or could I use a string. Once I have completed the my variable, what should I do to make a statement of choice. for example:

if the user chooses A.

should i proceed with and if statement followed by code.

if (A)
{
cout <<" enter the length: ";
cout <<"enter the width: ";
}

I have my programming completed, including the calculations, however I cannot make it work for a choice. for the user to choose either. A || B || C
closed account (10oTURfi)
http://www.cplusplus.com/doc/tutorial/control/

Scroll down to "The selective structure: switch."
let the letter be of type char and take the input. then you may use switch....case to perform jobs based on the input.
1
2
3
4
5
6
7
8
9
10
switch(letter)
{
  case 'A' : //code
                 break;
  case 'B' : //code
                 break;
  case 'C' : //code
                 break;
  default : //code
}
Last edited on
okay!

so I can use for example
char A, B, C = 0; or char letter; letter = A, B, C;

then for switch (A)

case 'A' : followed by my cout << statements and code?
closed account (10oTURfi)
more like this:
1
2
3
4
5
6
7
8
9
10
11
12
char letter;
cin >> letter;
switch(letter)
{
  case 'A' : //code
                 break;
  case 'B' : //code
                 break;
  case 'C' : //code
                 break;
  default : //code
}
got ya! thanks a lot, back to the keyboard. Happy Programming!
Topic archived. No new replies allowed.