Hi im working on a program for school and I feel like I had everything organized right and everything coded right but when i compile it tells me almost all the variables are not declared in this scope. I really did not want to ask for help, I've been trying to figure this out for about a week but i still haven't been able too. Any help would be much appreciated. Im sorry if the answer is really simple ive just started learning functions
In Main you are trying to pass variables to the functions but as the error says they are not declared. The same is the case in your calculations function and showresult function. The varaible you use need to either be passed to the function or declared in the function.
// This program demonstrates that changes to a function parameter
// have no affect on the original argument.
#include <iostream>
usingnamespace std;
// Function Prototype
void changeMe(int);
int main()
{
int number = 12;
// Display the value in number.
cout << "number is " << number << endl;
// Call changeMe, passing the value in number
// as an argument.
changeMe(number);
// Display the value in number again.
cout << "Now back in main again, the value of ";
cout << "number is " << number << endl;
return 0;
}
//**************************************************************
// Definition of function changeMe. *
// This function changes the value of the parameter myValue. *
//**************************************************************
void changeMe(int myValue)
{
// Change the value of myValue to 0.
myValue = 0;
// Display the value in myValue.
cout << "Now the value is " << myValue << endl;
}
The Output is...
number is 12
Now the value is 0
Now back in main again, the value of number is 12
Even though the parameter variable myValue is changed in the changeMe function, the argument number is not modified. The myValue variable contains only a copy of the number variable.
The changeMe function does not have access to the original argument. When only a copy of an argument is passed to a function, it is said to be passed by value . This is because the function receives a copy of the argument’s value and does not have access to the original argument.
I had done it like that before but i thought I was doing something wrong having so many declarations in one function. But is that considered okay since its a function with 3 sub functions.