First, you seem to have the right approach to the assignment, all the functions seem to be correct but I do see some errors and some useless stuff.
Second, next time post your code inside those [code ]*here[/code]. That way it will make it much easier for people to read your code.
Third, be a bit more detailed on your main problem because fixing the code is easy but I'm not sure how to direct you towards the right way if I don't know your issue.
For the Issues:
1. When using Switch/Case that are numbers, you don't close them with ' '
Bad:
1 2 3 4
|
case'1':
break;
case'2':
break;
|
Good
1 2 3 4
|
case 1:
break;
case 2:
break;
|
2. This is me being a math nerd here. Not sure how much code was given by the professor and what you need to keep but I assume every variable in this program has to be a double. There will be fractions/ decimal numbers being inputted into a calculator.
3. If you look at your prototype function of "Subtraction" The parameters don't match at all to your function delcaration. Your Prototype has int variables in its parameters but the body of the function uses double variables and passes by reference.
4. Last thing I noticed is that you are repeating
cout << "Please enter 2 numbers to divide" << endl;
twice, when the user inputs an option. The reason being that in the Switch/Case you are writing
cout << "Please enter 2 numbers to divide" << endl;
and you also have
cout << "Please enter 2 numbers to divide" << endl;
inside the body of the function.
Example of case
1 2 3 4 5
|
case '1':
int n1, n2;
cout << "Please enter two values to add" << endl;
cin >> n1 >> n2;
add();
|
Example of Function
1 2 3 4 5 6 7 8
|
void add()
{
int n1, n2, sum;
cout << "Please enter 2 numbers to add together " << endl;
cin >> n1 >> n2;
sum = n1 + n2;
cout << "The sum of these numbers is " << sum << endl;
}
|
both have the cout statement causing it to state it twice. Not sure how much was given by the professor but this should be my corrections.
Switch Case:
1 2 3
|
case '1':
add();
break;
|
Function declaration:
1 2 3 4 5 6 7 8
|
void add()
{
double n1, n2, sum; // changed them to double but if the professor says they have to be int, then do so.
cout << "Please enter 2 numbers to add together " << endl;
cin >> n1 >> n2;
sum = n1 + n2;
cout << "The sum of these numbers is " << sum << endl;
}
|
This also applies to the other Switch/Case statements and Function declarations. They all repeat the same cout statement everytime. So fix all of them
The code should be able to run with those corrections.