Hi everyone: this is the prompt to create the program.
Description
Write a simple calculator so that a user can input a number with two values separated by an operator and the computer print out the proper answer. The calculator should round answers to two decimal places. Your calculator should include the ^ operator for exponentiation. All calculations should be done in the appropriately named function. Four of the results should be printed in main( ) and one result printed directly from within the function. Be sure to check for impossibilities in division and exponentiation.
The user should be able to use the calculator until they desire to quit.
Required Functions: add( ), subtract( ), multiply( ), divide( ), exponentiate( )
Required Operators: +, -, *, /, ^
//Final Program
//Program # 5
//I have really enjoyed this class!!
//This program is a simple calculator that allows a user to input a number with two values seperated by an operator and the computer print out the proper answer.
double main(void)
{
//Introduce program
cout <<"Welcome to Brenda's C++ Simple Calculator"<< endl;
cout <<" Program adds, subtracts, multiplies, divides, & exponentiates" << endl;
cout <<"---------------------------------------------------------------" << endl << endl;
//Ask user for the first value
cout << endl;
cout << "Enter the first value: " << endl;
cin >> value_x;
//Ask user for the second value
cout << endl;
cout << "Enter the second value: " << endl;
cin >> value_y;
//Ask the user to enter the operation they wish to perform
//While loop
//If statement
cout << endl;
cout << "Please enter the operation you wish to perform ( + , - , * , / , ^ ): ";
cout << "If you would like to exit the calculator please enter Q or q"<< endl;
cin >> operation;
do while ((operation != 'Q') || (operation != 'q'))
{
/*if (operation == '+')
{
z = Add_function(value_x,value_y);
}*/
if (operation == '-')
{
z= Subtract_function(value_x,value_y);
cout << "The value of" << value_x << operation << value_y << "=" << z << endl;
}
else if (operation == '*')
{
z= Multiply_function(value_x,value_y);
cout << "The value of" << value_x << operation << value_y << "=" << z << endl;
}
else if (operation == '/')
{
z= Divide_function(value_x,value_y);
cout << "The value of" << value_x << operation << value_y << "=" << z << endl;
}
else if (operation == '^')
{
z= Exponent_function(value_x,value_y);
cout << "The value of" << value_x << operation << value_y << "=" << z << endl;
}
else
{
cout << endl;
cout << "Sorry, that operation is not recognized!" << endl;
cout << "Do you want to perform another calculation? (Y or N)";
cin >> response;
cin.get ();
while ((response == Y) || (response == y));
{
cout << "Please enter the operation you wish to perform" << endl;
cin >> operation;
cout << endl << endl;
}
}
}
}
//functions
double Add_function(double x,double y)
{ double h;
h=x+y;
cout << "The value of" << x << "+" << y << "=" << h << endl;
return h;
}
This is the second possibility of my program
i keep receiving this error
cpp(101) : error C2059: syntax error : '}'
warning C4508: 'main' : function should return a value; 'void' return type assumed
if i take out the "}"
i get the following error
.cpp(133) : fatal error C1004: unexpected end of file found
//Program # 5
//I have really enjoyed this class!!
//This program is a simple calculator that allows a user to input a number with two values seperated by an operator and the computer print out the proper answer.
//Introduce program
cout <<"Welcome to Brenda's C++ Simple Calculator"<< endl;
cout <<" Program adds, subtracts, multiplies, divides, & exponentiates" << endl;
cout <<"---------------------------------------------------------------" << endl << endl;
//Ask user for the first value
cout << endl;
cout << "Enter the first value: " << endl;
cin >> value_x;
//Ask user for the second value
cout << endl;
cout << "Enter the second value: " << endl;
cin >> value_y;
//Ask the user to enter the operation they wish to perform
//While loop
//If statement
cout << endl;
cout << "Please enter the operation you wish to perform ( + , - , * , / , ^ ): ";
cout << "If you would like to exit the calculator please enter Q or q"<< endl;
cin >> operation;
do while ((operation != 'Q') || (operation != 'q'))
{
/*if (operation == '+')
{
z = Add_function(value_x,value_y);
}*/
if (operation == '-')
{
z= Subtract_function(value_x,value_y);
cout << "The value of" << value_x << operation << value_y << "=" << z << endl;
}
else if (operation == '*')
{
z= Multiply_function(value_x,value_y);
cout << "The value of" << value_x << operation << value_y << "=" << z << endl;
}
else if (operation == '/')
{
z= Divide_function(value_x,value_y);
cout << "The value of" << value_x << operation << value_y << "=" << z << endl;
}
else if (operation == '^')
{
z= Exponent_function(value_x,value_y);
cout << "The value of" << value_x << operation << value_y << "=" << z << endl;
}
else
{
cout << endl;
cout << "Sorry, that operation is not recognized!" << endl;
cout << "Do you want to perform another calculation? (Y or N)";
cin >> response;
cin.get ();
while ((response == Y) || (response == y));
{
cout << "Please enter the operation you wish to perform" << endl;
cin >> operation;
cout << endl << endl;
}
}
}