trying to use a void function below. How do I correct scope not declared for numYears and numChildren?
4#include <iostream>
5#include <cmath>
6using namespace std;
7
8// Function prototype
9void tellFortune(int);
10
11/***** main *****/
12int main()
13{
14 int numYears,
15 numChildren;
16
17 cout << "This program can tell your future. \n"
18 << "Enter two integers separated by a space: ";
19
20 cin >> numYears >> numChildren;
21
22 tellFortune(numYears, numChildren);
23
24
25 return 0;
26}
27
28/***** tellFortune *****/
29void tellFortune()
30{
31 numYears = abs(numYears) % 5; // Convert to a positive integer 0 to 4
32 numChildren = abs(numChildren) % 6; // Convert to a positive integer 0 to 5
33
34 cout << "\nYou will be married in " << numYears << " years "
35 << "and will have " << numChildren << " children.\n";
36}
For this, it doesn't seem like it needs to be pass by reference as it doesn't need them again.
Something like this will also work:
1 2 3 4
|
void tellFortune(int numYears, int numChildren)
{
your code...
}
|
Also make sure that both the function name and description match!
You have
void tellFortune(int);
and
void tellFortune()
when it should be
1 2 3 4 5 6 7
|
void tellFortune(int numYears, int numChildren);
AND
void tellFortune(int numYears, int numChildren)
{}
|
Last edited on