function that reads in numbers

#include <iostream>
#include <iomanip>
using namespace std;

//prototype first function
double readInNumber(double x);
//prototype second function
double processNumbers(double a, double b, int c);
int main(){

double oldAmount;
double newAmount;
double initialAmount;
double rate;
//declare variable numberOfYears as int
int numberOfYears;
//Ask user to enter the number of years
cout << "Enter in the number of years.\n";
//read in numberOfYears
cin >> numberOfYears;
cout << "\n";
//1st function will be called here
//It will read in the initial amount
cout << "Enter in the initial amount";
readInNumber(initialAmount);





return 0;

}//main

double readInNumber(double x)
{cin >> x;
return x;
}




I am having trouble with the function readInNumber. All it is suppose to do is read in the number that the user enters for 'initialAmount'. But, when I run this program this message comes up. "Run-Time Check Failure #3- The variable 'initialAmount' is being used without being initialized."

I thought the whole point of it not being initialized is so that the function can initialize it. I am running in Visual Studio 2010.

If anyone has any advice it would be greatly appreciated.

Thanks in advance.
Last edited on
bump
Make readInNumber a function that doesn't take any arguments. Instead of calling it in main by saying readInNumber(initialAmount); say initialAmount = readInNumber();
You need to pass the value by reference not value in to readInNumber. Also look up cin.ignore()
I got it. Much thanks to the both of you for your time.
Topic archived. No new replies allowed.