The purpose of this program is to illustrate one use of void functions and reinforce use of value returning functions.
The program will function as a calculator; therefore, it is to invoke a void function (without parameters) to present the following menu for the user :
Welcome to the CIS 151 calculator
To make a selection, enter the number and press enter
1: Add 2 numbers
2: Subtract a number from another
3: Multiply 2 numbers
4: Divide 2 numbers
5. Modulus of 2 numbers
6. Raise a number to a power
7. Quit the program.
Then, based upon the user's choice, a value returning function with 3 parameters will called and a value will be returned to the mainline.
Next, a void function, with parameters will be called to output a message in one of the following formats :
The sum of a and b is c.
The difference between a and b is c.
The product of a and b is c.
a divided by b is c.
a modulus b is c.
a raised to the power of b is c.
Note : a and b will be input as double numbers. However, when processing option 5, store the numbers in integer variables and then calculate the modulus using the the integer variables.
int main(int argc, char** argv)
{
int choice;
double a, b;
double c;
int main()
{
int choice; //menu choice
//constants for menu choices
cout<< "Add two numbers" = 1,
cout<< "Subtract a number from another" = 2,
cout<< "Multiply two numbers" = 3,
cout<< "Divide two numbers" = 4,
cout<< "Modulus of two" = 5;
cout<< "Raise a number to a power"= 6;
cout<< "Quit the program"= 7
cin>> choice;
}
int choice (int a, int b, int c)
{
cout<< "Entertwo numbers"
cin>> a, b;
return main;
}
void answers (int& a, int& b, int c)
{
if (choice == 1)
c= a+b;
cout<< ""<< c<< endl;
if (choice == 2)
c= a-b;
cout<< ""<< c<< endl;
if (choice == 3)
c= a*b;
cout<< ""<< c<< endl;
if (choice == 4)
c= a/b;
cout<< ""<< c<< endl;
if (choice == 5)
c= a% b;
cout<< ""<< c<< endl;
if (choice == 6)
c= pow (a, b);
cout<< ""<< c<< endl;
if (choice == 7)
break;
}
return 0;
}
// I also can't do return functions so can someone please help me on how to do this?