Oct 12, 2016 at 4:48pm UTC
// I just want my program to repeat the original question after a Switch statement has been performed. I tried using a for while loop but i couldnt get it to work...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
void main()
{
int num1;
double num2;
char select;
cout << "Welcome to my Trigonometric Function Calculator ! " << endl;
cout << "Please select a selection to be performed \n\n S : Sine, \n C : Cosine,\n T : Tangent, \n E : Exit \n\n " ;
cout << "Please enter your selection " ;
cin >> select;
switch (select)
{
case 'S' :
cout << " You selected Sine function" << endl;
cout << " Please Enter a number in degrees " ;
cin >> num1;
num2 = (sin(num1 * 0.0174533));
cout << " sin(" << num1 << "degrees ) = " << fixed << setprecision(4) << num2 <<endl;
break ;
case 'C' :
cout << " You selected Cosine function" << endl;
cout << " Please Enter a number in degrees " ;
cin >> num1;
num2 = (cos(num1 * 0.0174533));
cout << " cos(" << num1 << "degrees ) = " << fixed << setprecision(4) << num2 << endl;
break ;
case 'T' :
cout << " You selected Tangent function" << endl;
cout << " Please Enter a number in degrees " ;
cin >> num1;
num2 = (tan(num1 * 0.0174533));
cout << " tan(" << num1 << "degrees ) = " << fixed << setprecision(4) << num2 << endl;
break ;
case 'E' :
cout << " You chose to exit program. Adios!" << endl;
break ;
default :
cout << "You typed in an invalid number." << endl;
break ;
}
}
Last edited on Oct 12, 2016 at 5:37pm UTC
Oct 12, 2016 at 5:38pm UTC
I tried doing it on my own , but removed it so it would look alittle cleaner for others to see.
As of now i dont have any loops. but i want to implement them
Oct 13, 2016 at 5:03am UTC
To repeat the switch statement declare a bool variable, say fQuit, initialized with value false
Then run a while loop before your first cout statment:
while(!fQuit){
// your code goes in here
}
And for case 'E' set fQuit = true so that if you choose E your loop will be terminated
Edit: your main() function should return int btw
Last edited on Oct 13, 2016 at 5:04am UTC