I am having a problem with this program reading in the first line of my infile. It is skipping automatically to read the second line and also adding a line in the end that I have no idea where it would have come from, its an exponential number with no relation at all to my infile. The program is supposed to read 4 change amounts from infile and convert to the fewest change amounts. Any help would be greatly appreciated. The first line that it is skipping is a value of 0.49 fron the infile. Thank you
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
ifstream infile;
ofstream outfile;
int sumQuarter, sumDime, sumNickle, sumPenny, amount;
float dollar;
const int dollar2cent = 100;
const int quarter = 25;
const int dime = 10;
const int nickle = 5;
const int penny = 1;
int inQuarter(int);
int inDime(int);
int inNickle(int);
int inPenny(int);
float getData();
int printChange();
int main()
{
infile.open ("money.dat"
outfile.open ("money.out"
dollar = getData ();
while (infile)
{
dollar = getData ();
amount = dollar * dollar2cent;
sumQuarter = inQuarter(amount);
sumDime = inDime(amount);
sumNickle = inNickle(amount);
sumPenny = inPenny(amount);
printChange();
}
}
int inQuarter(int amount)
{
int num;
num = amount / quarter;
return num;
}
int inDime(int amount)
{
int num;
amount = amount % quarter;
num = amount / dime;
return num;
}
int inNickle(int amount)
{
int num;
amount = amount % quarter;
amount = amount % dime;
num = amount / nickle;
return num;
}
int inPenny(int amount)
{
int num;
amount = amount % quarter;
amount = amount % dime;
amount = amount % nickle;
num = amount;
return num;
}
float getData()
{
float dollar;
infile >> dollar;
return dollar;
}
int printChange()
{
outfile << "$" << dollar << "is changed to" << sumQuarter << "quarter(s)" <<
sumDime << "dime(s)" << sumNickle << "nickle(s)" << sumPenny << "penny(s)" << endl;
return 0;
}
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
ifstream infile;
ofstream outfile;
int sumQuarter, sumDime, sumNickle, sumPenny, amount;
float dollar;
const int dollar2cent = 100;
const int quarter = 25;
const int dime = 10;
const int nickle = 5;
const int penny = 1;
int inQuarter(int);
int inDime(int);
int inNickle(int);
int inPenny(int);
float getData();
int printChange();
int main()
{
infile.open ("money.dat"
outfile.open ("money.out"
dollar = getData ();
while (infile)
{
dollar = getData ();
amount = dollar * dollar2cent;
sumQuarter = inQuarter(amount);
sumDime = inDime(amount);
sumNickle = inNickle(amount);
sumPenny = inPenny(amount);
printChange();
}
}
int inQuarter(int amount)
{
int num;
num = amount / quarter;
return num;
}
int inDime(int amount)
{
int num;
amount = amount % quarter;
num = amount / dime;
return num;
}
int inNickle(int amount)
{
int num;
amount = amount % quarter;
amount = amount % dime;
num = amount / nickle;
return num;
}
int inPenny(int amount)
{
int num;
amount = amount % quarter;
amount = amount % dime;
amount = amount % nickle;
num = amount;
return num;
}
float getData()
{
float dollar;
infile >> dollar;
return dollar;
}
int printChange()
{
outfile << "$" << dollar << "is changed to" << sumQuarter << "quarter(s)" <<
sumDime << "dime(s)" << sumNickle << "nickle(s)" << sumPenny << "penny(s)" << endl;
return 0;
}