Here is my program, I am having trouble with it. Whenever you type in 4.5 as an option, it should restate the menu and have you enter in a valid option. The only problem is, after the menu comes back up, I type in a valid option and it closes....
cout<<"This Program is designed to calculate the area of various shapes" <<endl;
cout<<"" <<endl;
cout<<"" <<endl;
cout<<"**********Options**********" <<endl;
cout<<"1 Circle" <<endl;
cout<<"2 Rectangle" <<endl;
cout<<"3 Triangle" <<endl;
cout<<"4 Quit" <<endl;
cout<<"***************************" <<endl;
cout<<"Which would you like to select?" <<endl;
cin>>option;
while (option==1)
{
cout<<"What is the radius of your circle?" <<endl;
cin>>radius;
AC=radius*radius*3.14159265;
cout<<AC;
cout<<" is the area of your circle" <<endl;
cout<<"" <<endl;
system("Pause");
cout<<"" <<endl;
cout<<"" <<endl;
cout<<"" <<endl;
cout<<"**********Options**********" <<endl;
cout<<"1 Circle" <<endl;
cout<<"2 Rectangle" <<endl;
cout<<"3 Triangle" <<endl;
cout<<"4 Quit" <<endl;
cout<<"***************************" <<endl;
cout<<"Which would you like to select?" <<endl;
cin>>option;
}
while (option==2)
{
cout<<"What is the Lenght of your Rectangle?" <<endl;
cin>>length;
cout<<"What is the Width of your Rectangle?" <<endl;
cin>>width;
AR=length*width;
cout<<AR;
cout<<" is the area of your rectangle" <<endl;
cout<<"" <<endl;
system("Pause");
cout<<"" <<endl;
cout<<"" <<endl;
cout<<"**********Options**********" <<endl;
cout<<"1 Circle" <<endl;
cout<<"2 Rectangle" <<endl;
cout<<"3 Triangle" <<endl;
cout<<"4 Quit" <<endl;
cout<<"***************************" <<endl;
cout<<"Which would you like to select?" <<endl;
cin>>option;
}
while (option==3)
{
cout<<"What is the height of your Triangle?" <<endl;
cin>>height;
cout<<"What is the base of your Triangle?" <<endl;
cin>>base;
AT=0.5*base*height;
cout<<AT;
cout<<" is the area of your triangle"<<endl;
cout<<"" <<endl;
system("Pause");
cout<<"" <<endl;
cout<<"" <<endl;
cout<<"**********Options**********" <<endl;
cout<<"1 Circle" <<endl;
cout<<"2 Rectangle" <<endl;
cout<<"3 Triangle" <<endl;
cout<<"4 Quit" <<endl;
cout<<"***************************" <<endl;
cout<<"Which would you like to select?" <<endl;
cin>>option;
}
while (option==4)
{
cout<<"" <<endl;
cout<<"" <<endl;
cout<<"Thank You and Goodbye";
Sleep(2000);
return 0;
}
while (option>4)
{
cout<<"" <<endl;
cout<<"Please Select a Valid Option" <<endl;
cout<<"" <<endl;
cout<<"" <<endl;
cout<<"**********Options**********" <<endl;
cout<<"1 Circle" <<endl;
cout<<"2 Rectangle" <<endl;
cout<<"3 Triangle" <<endl;
cout<<"4 Quit" <<endl;
cout<<"***************************" <<endl;
cout<<"Which would you like to select?" <<endl;
cin>>option;
}
while (option <=0)
{
cout<<"" <<endl;
cout<<"Please Select a Valid Option" <<endl;
cout<<"" <<endl;
cout<<"" <<endl;
cout<<"**********Options**********" <<endl;
cout<<"1 Circle" <<endl;
cout<<"2 Rectangle" <<endl;
cout<<"3 Triangle" <<endl;
cout<<"4 Quit" <<endl;
cout<<"***************************" <<endl;
cout<<"Which would you like to select?" <<endl;
cin>>option;
}
}
while(option!=4) // check if user quits
{
switch(option){
case 1: calCircle(); // function for calculating circle
case 2:calRectangle(); // function for calculating rectangle
case3:calTriangle(); // function for calculating triangle
}
}
If the person types in 4.5 then your program will read in the 4 because you asked it for an int. 4 is a legal int so it will run with that. The remaining .5 will still be there for when you ask for more input.
What a mess.
You should rewrite and resubmit your code in line with Cody39e (and others) suggestions because the improvement will be significant. Also find an alternative for system ("pause") to keep the window open.