C++!!!! PLEASE HELP I am not allowed to use global variables!! Phase 1 Write a p
ID: 3589321 • Letter: C
Question
C++!!!!
PLEASE HELP
I am not allowed to use global variables!!
Phase 1
Write a program that prints a menu. Based on the menu item selected by the user, the program should
request the required inputs from the user
call the appropriate function
print the function’s result (from the main program NOT the function)
For example, if the user selections the sum function, then your program will ask them for two numbers to be added together, call the sum function, and finally print the sum function’s result.
NOTE: In case of a typo on here – make your output match the CA output!
The functions to implement are:
Simple Sum: Takes two int parameters and returns their sum. You will need to ask the user for two integers before calling this function.
Simple Division: Takes two int parameters and returns their floating point quotient (e.g., 10/3 returns 3.33). You will need to ask the user for two integers before calling this function.
Complex Division: Takes four int parameters, sums the first three parameters and then divides the sum by the fourth parameter. Returns the floating point quotient (e.g., (10 + 7 + 5) / 4 returns 5.5). You will need to ask the user for three integers and an integer divisor before calling this function.
(note - all function parameters will need to match the requirements of the assignment. - thus you do not use arrays in this assignment anywhere)
Design:
It is imperative that each of these three operations be in their own function.
You should have an additional function that determines the operation type by printing the menu and then returning the integer that the user selects.
Your main program should use a switch statement that switches on the numeric integer entered by the user to select the correct function to call.
Your switch statement should also gather the inputs from the user before calling the function.
You will print the result returned by the function in your switch statement.
All function prototypes will be listed at the top of your code (after using namespace std;) and all your function definitions to be placed after main.
Please help me debug the code I have written for this so far. My Do while is not working, it is supposed to keep running that loop multiple times so the user can do multiple operations. I am not sure how to do this. Also I am having an error with simple division "Invalid operands of types ‘int’ and ‘’ to binary ‘operator<<’ "
#include
#include
using namespace std;
int main(){
int menu();
int SimpleSum(int, int);
double SimpleDivision(int, int);
//double ComplexDivision(int, int, int, int);
int int_1;
int int_2;
switch(menu())
{
case 1:
cout << "Please enter two integers:" << endl;
cin >> int_1;
cin >> int_2;
SimpleSum(int_1, int_2);
cout << "sum = " << SimpleSum(int_1, int_2) << endl;
break;
case 2:
cout << "Please enter two integers: " << endl;
cin >> int_1;
cin >> int_2;
SimpleDivision(int_1, int_2) << endl;
cout << "quotient = " << SimpleDivision(int_1, int_2);
break;
/* case 3:
ComplexDivision();
break; */
}
return 0;
}
//////////////////////////////////////////////////////////////////
int menu() {
int menu_choice;
do{
cout << "Please make a selection from the following menu" << endl;
cout << endl;
cout << "1. Simple Sum "
"2. Simple Division "
"3. Complex Division "
"4. Quit " << endl;
cout << "Enter the number of the operation you wish to perform: " ;
cin >> menu_choice;
return menu_choice;
} while (menu_choice != 4);
return 0;
}
///////////////////////////////////////////////////////////////////
int SimpleSum(int int_1, int int_2){
int sum;
sum = int_1 + int_2;
return sum ;
}
///////////////////////////////////////////////////////////////////
double SimpleDivision( int int_1, int int_2){
double quotient;
quotient = (int_1 / int_2) ;
return quotient;
}
///////////////////////////////////////////////////////////////////
Explanation / Answer
Program:--
#include<iostream>
#include<cstdlib>
using namespace std;
//All function prototypes
int menu();
int SimpleSum(int, int);
double SimpleDivision(int, int);
double ComplexDivision(int, int, int, int);
int main()
{
int ch;
do{
int int_1,int_2,int_3,int_4;
ch=menu(); //calling menu return value stored in ch
switch(ch) //switch with ch value
{
case 1:
cout << "Please enter two integers:" << endl;
cin >> int_1;
cin >> int_2;
cout << "sum = " << SimpleSum(int_1, int_2) << endl; //call for simple some and print sum
break;
case 2:
cout << "Please enter two integers: " << endl;
cin >> int_1;
cin >> int_2;
cout << "quotient = " << SimpleDivision(int_1, int_2); //call for simpledivision and print quetient
break;
case 3:
cout << "Please enter three integers: " << endl;
cin >> int_1;
cin >> int_2;
cin >> int_3;
cout << "Please enter one integer divisor: " << endl;
cin >> int_4;
cout<<"quotient = "<< ComplexDivision(int_1, int_2, int_3, int_4); //call for complex division and print quetient
break;
case 4:exit(0); //terminate program
}
}while(ch!=4); //while ch not equal to 4 repeat the same process
return 0;
}
double ComplexDivision(int a, int b, int c, int d)
{
int sum=a+b+c; //sum the first 3 values
double quetient=(double)sum/d; //convert the sum to double and divide with 4th value
return quetient; //return quetient
}
double SimpleDivision( int int_1, int int_2)
{
double quotient;
quotient =((double)int_1 /(double) int_2) ; //convert integers to double and divide
return quotient; //return quetient
}
int SimpleSum(int int_1, int int_2)
{
int sum;
sum = int_1 + int_2; //sum the two values
return sum ; //return sum
}
int menu()
{
int menu_choice;
cout << " Please make a selection from the following menu" << endl;
cout << endl;
cout << "1. Simple Sum 2. Simple Division 3. Complex Division 4. Quit "<< endl;
cout << "Enter the number of the operation you wish to perform: " ;
cin >> menu_choice; //read user choice
return menu_choice; //return choice
}
Output:--
Please make a selection from the following menu
1. Simple Sum
2. Simple Division
3. Complex Division
4. Quit
Enter the number of the operation you wish to perform: 1
Please enter two integers:
5
6
sum = 11
Please make a selection from the following menu
1. Simple Sum
2. Simple Division
3. Complex Division
4. Quit
Enter the number of the operation you wish to perform: 2
Please enter two integers:
11
2
quotient = 5.5
Please make a selection from the following menu
1. Simple Sum
2. Simple Division
3. Complex Division
4. Quit
Enter the number of the operation you wish to perform: 2
Please enter two integers:
10
2
quotient = 5
Please make a selection from the following menu
1. Simple Sum
2. Simple Division
3. Complex Division
4. Quit
Enter the number of the operation you wish to perform: 3
Please enter three integers:
1
2
3
Please enter one integer divisor:
4
quotient = 1.5
Please make a selection from the following menu
1. Simple Sum
2. Simple Division
3. Complex Division
4. Quit
Enter the number of the operation you wish to perform: 3
Please enter three integers:
1
2
3
Please enter one integer divisor:
2
quotient = 3
Please make a selection from the following menu
1. Simple Sum
2. Simple Division
3. Complex Division
4. Quit
Enter the number of the operation you wish to perform: 4
Process exited normally.
Press any key to continue . . .
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.