Problem with function
| Sketchy Ninja (3) | |||
| When i run the program through all of the formulas work but if i dont hit the right number to goto the menu it says not an option and returns to the choose screen but the second time through it doesnt work also when i hit 5 it doesnt exit the program it asks do u want to to it again. Can anybody help me with these errors. heres my code so far... #include <cstdlib> #include <iostream> #include <windows.h> #include <iomanip> #include <math.h> #include <string> using namespace std; float area, base, height, radious, base_1, base_2 ; int formula; char again; string units; int Main() { cout<<setw(50)<<"Choose The Formula For You:\n"; cout<<setw(43)<<"[1]Rectangle\n"; cout<<setw(40)<<"[2]Circle\n"; cout<<setw(42)<<"[3]Triangle\n"; cout<<setw(43)<<"[4]Trapazoid\n"; cout<<setw(38)<<"[5]Exit\n"; cin>>formula; cin.clear(); } int option() { switch (formula) { case 1: cout<<setw(52)<<"What are your units:"; cin>>units; cout<<"\n\n"; cout<<setw(48)<<"Enter your base:"; cin>>base; cout<<"\n\n"<<setw(50)<<"Enter your height:"; cin>>height; area=base*height; cout<<"\n\n"<<setw(62)<<"The area of your rectangle is:"<<area<<" "<<units<<" Squared\n"; Sleep(5000); system("cls"); break; case 2: cout<<"\n\n\n"; cout<<setw(49)<<"What are your units:"; cin>>units; cout<<"\n\n\n"; cout<<setw(45)<<"Enter your base:"; cin>>base; cout<<"\n\n\n"; cout<<setw(47)<<"Enter your height:"; cin>>height; area=(.5)*(base*height); cout<<"\n\n\n"; cout<<setw(58)<<"The area of your triangle is:"<<area<<" "<<units<<" Squared\n"; Sleep(5000); system("cls"); break; case 4: cout<<setw(52)<<"What are your units:"; cin>>units; cout<<"\n\n"; cout<<setw(45)<<"Enter base 1:"; cin>>base_1; cout<<"\n\n"; cout<<setw(45)<<"Enter base 2:"; cin>>base_2; cout<<"\n\n"; cout<<setw(50)<<"Enter your height:"; cin>>height; cout<<"\n\n"; area=(.5*height)*(base_1+base_2); cout<<setw(62)<<"The area of your rectangle is:"<<area<<" "<<units<<" Squared\n";; Sleep(5000); system("cls"); break; case 5: return 0; break; default: cout<<"NOT AN OPTION"; Sleep(1000); Main(); break; } } int main(int argc, char *argv[]) { do { cin.clear(); Main(); option(); again: cout<<"would you like to do this again [y] or [n]?"; cin>>again; }while (again=='y' || again=='Y'); switch (again) { case 'n': return 0; default: return 0; break; } } | |||
| PoliticalDestruction (10) | |||
That works, i just didn't add that repeat thing at the end. Hope I helped.
| |||
This topic is archived - New replies not allowed.
