I am having trouble figuring out why my code asks me to enter a number twice. I need to figure out how to make it just square the input from getValue();
#include <iostream>
#include <cmath>
usingnamespace std;
int getValue();
void squareValue();
int main()
{
int num;
num = getValue();
cout << "The value entered is " << num << endl;
squareValue();
return 0;
}
int getValue()
{
int val;
cout << "Enter a number " << endl;
cin >> val;
return val;
}
void squareValue()
{
cout << "The value squared is " << pow(getValue(), 2) << endl;
return;
}
You're calling getValue() twice, once on line 13 and again on line 33.
I suggest modifying the squareValue() function's signature and passing a value to it.