Hey everyone, I need some help with functions. I was instructed to add on to existing code (my addition is at the very bottom). Whenever I compile it, however, the computer ignores what I put at the bottom. How do I get it to read what I added at the very bottom? Thanks in advance!
#include <iostream>
#include <cmath>
#include <string>
usingnamespace std;
// Function prototypes. Both functions use reference variables as parameters
void doubleNum(int &);
void getNum(int &);
void zValue(double sampleMean, double populationMean, double populationSTDV, double sampleSize);
int main()
{
int value, wait;
// Get a number and store its value
getNum(value);
// Double the number stored in value
doubleNum(value);
// Display the resulting number.
cout << "The value doubled is " << value << endl;
cout << "Enter an integer to terminate : ";
cin >> wait;
return 0;
}
// ***************************************************************
// * Definition of getNum
// * The parameter userNum is a reference variable. The user is
// * asked to enter a number, which is stored in userNum
// ***************************************************************
void getNum(int &userNum)
{
cout << "Enter a number: ";
cin >> userNum;
}
// ***************************************************************
// * Definition of doubleNum
// * The parameter refVar is a reference variable. The value in
// * refVar is doubled
// ***************************************************************
void doubleNum(int &refVar)
{
refVar *= 2;
}
//****************************************************************
//
// New Function with Loop (My Addition)
//
//****************************************************************
void zValue(double sampleMean, double populationMean, double populationSTDV, double sampleSize)
{
const string message1 = "Enter your vaules for the Z score.";
double totalZ = ((sampleMean - populationMean) / (populationSTDV) / sqrt(sampleSize));
cout << "Let's calculate the Z value." << endl;
cout << message1 << endl;
cin >> sampleMean,
populationMean,
populationSTDV,
sampleSize;
cout << "The Z value is: " << totalZ << ".\n";
//Loop
int Yes = 1;
int No = 2;
int exitLoop;
cout << "Would you like to terminate the program?" << endl;
cout << "Press '1' for yes and any other number for no.";
cin >> exitLoop;
while (exitLoop < 1 || exitLoop > 1)
{
cout << message1;
cin >> exitLoop;
}
}
The computer isn't necessarily ignoring your function. You have just not called the function from anywhere. Remember you need to call the function just like the other 2 functions are.