I'm trying to call a function into another function but It keeps giving me that the two variables I have in in the "read_and_total" function I'm tring to call into the "read_and_process" aren't initialized( int D and int P)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
void read_and_process (int acct, int& timeUsed, int& dataUsed, bool& valid)
int error;
valid = validate_account(acct);
if (!valid)
{
cout << "The account Number provided is invalid" << endl;
}
cin >> timeUsed >> dataUsed >> error;
if (error == 1)
{
valid = false;
cout << "The account record has an error" << endl;
}
}
You need to set the starting values of D and P. Perhaps each can be set at zero? The reason is int D for arguments sake allocates storage but the contents of that storage will be junk unless you initialize it. Starting with junk and then adding 1 to it as in line 7 of the second listing just makes more junk.
It's not clear to me which function you are calling so I can only guess.
But if you have a line in void read_and_process ( ... ) then you would write read_and_ total(regularTimeCost, regulaDatacost, acctNum, dataUsed, timeUsed)
If you are in void read_and_ total( ... ) and want to call void read_and_process ( ... ) repeatedly in a loop then you would write:
1 2 3 4 5
for( int i = start; i < something; i change)
{
read_and_process (acct, timeUsed, dataUsed, valid);
... whatever other stuff
}
Don't forget also that you have to supply values to the various parameters being passed.