I have written out the program, the program compiles and when it runs, it'll run the prompt, and when you input a number and press enter, it'll go to the next line and it will be blank. Can someone tell me what I'm doing wrong?
ex.
What multiples are we adding? 3
Then nothing until I terminate it.
Here's my code, can I have some help? That'd be great.
#include <iostream>
using namespace std;
float getNumber();
float getAnswer(float);
void display(float, float);
/**********************************************************************
* Add text here to describe what the function "main" does. Also don't forget
* to fill this out with meaningful text or YOU WILL LOSE POINTS.
***********************************************************************/
int main()
{
float x;
float z;
getNumber();
getAnswer(x);
display(x,z);
return x, z;
}
float getNumber()
{
float x;
cout << "What multiples are we adding? ";
cin >> x;
return x;
}
float getAnswer(float x)
{
float z;
int i;
int total = 0;
for ( i = 1, z = 0; z < 100; i++)
{
total += z;
z = x * i;
}
return x, z;
void display(float x, float z)
{
cout << "The sum of multiples of " << x
<< " less than 100 are: " << z << endl;
}
The reason its not moving onto the next step is because the variable x is undefined. The reason for this is while you're returning x in the getNumber() function you arn't returning it to anything.
When you make a variable in a function that variable is only accessible to that function so while there's an in getNumber() and in main() that doesn't make them the same variable.
Try changing: getNumber();
to x=getNumber();
This will put the variable that the function getNumber() is returning into the variable x.
Also when posting code here always put it inside [code] formatting.