#include <iostream>
#include <string>
usingnamespace std;
double displayDivision(double x,double y)
{
double answer;
answer = (x / y);
// if (divisor == 0)
// {
//cout << "Error: Attempt to divide by zero!" << endl;
// }
// else
//
}
int main ()
{
// put this is in a do..while function?
double dividend, divisor;
cout << "Enter the dividend: ";
cin >> dividend;
cout << "Enter the divisor: ";
cin >> divisor;
// call function
// cout << "Do you want to continue (y/n)?
// cin >> response;
// if (response == "n") || (response == "N")
// // return 0;
}
My first problem that I run into is that I'm supposed to have my function display the division and not return it. This means that instead of return; it's going to simply be a cout << right?
When I try to run this, I get an error that says my function must return a value.
This means that instead of return; it's going to simply be a cout << right?
Yes
When I try to run this, I get an error that says my function must return a value.
If you don't want a function to return anything use a void function.
Check for zero divisor before doing the calculation.
You will need to use a loop in the main function, which runs until the user wants to continue (I recommend a do-while loop, since you don't wanna ask the user if he/she want's to continue in the first iteration). In the loop you first ask for user input, call your function, then ask the user if he/she want's to continue.
Good luck, come back if you have any further troubles.
I've read that at least a dozen times as it's been suggested before. I know what a function does and how to reference them in the examples they give. The problem says that I have to print this in the function without returning the information.
The instructions tell me not to call the function.
Where do they tell that?
xcrossmyheartx's compiler said:
\assignment27.cpp(19) : error C4716: 'displayDivision' : must return a value
As R0mai said, use a void function. A void function is a function that doesn't return a value. It doesn't mean that it can't take any arguments. That's how your function's signature should look like: