I need help creating a loop for this program, I can get the program to execute the desired function but after the function is executed I can't get it to loop back to the menu to select another function. I've tried several do-while statements but I keep getting "error expected 'while'".
Purpose of the program :
Creating a menu driven program that calculate sqrt, tan,
log, log10, and log with user specified base.
Section 1 Display a menu, then receive a selection.
Section 2 Calculate the equation, or generate an error message when
other than the specified operation is entered.
Section 3 Show the result on the screen.
Section 4 Repeat Secion 1 through Section 3 unless user decides to
quit.
(Hint: Use a decision and a loop statements.)
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>
using namespace std;
void main()
{
const double pi = 3.1415926535897932384626433832795;
int select;
double num1, num2, ans;
cout<<"Please enter a value : ";
cin>>num1;
cout<<"Menu : Please select a funtion to be executed:" <<endl << "1. sqrt" <<endl<< "2. tan" <<endl<< "3. natural log" <<endl<<
"4. log10" <<endl<< "5. log base specified by user"<<endl<< "6. Exit"<<endl;
cin>>select;
if(select > 6 || select < 1)
{
cout << "Scooby-Dooby Doo Doo, you made a boo boo!";
}
else {
while (select !=6)
{
if (select == 1)
cout<<"sqrt (" <<num1<<")="<<(sqrt(num1))<<endl;
if (select == 2)
cout<<"tan (" <<num1<<")="<<tan(num1*pi/180)<<endl;
if (select == 3)
cout<<"natural log("<<num1<<") = "<<log(num1*(pi/180))<<endl;
if (select == 4)
cout<<"log10 (" <<num1<< ") = "<<log10(num1*(pi/180))<<endl;
if (select == 5)
cout<<" Please enter the value for the base "<<endl;
cin>>num2;
cout<<"base value("<<num2<<") log of ("<<num1<<") = "<<log(num1*(pi/180))/log(num2*(pi/180));
if (select == 6)
break ;
}
}}//main
|