I am doing C++ program which reads infinite while loop,
After letting user enter the desired month and year. The loop become infinite and only output "AAAAA...."
Textfile(input)
1 9 2017|0112233445|20.00 5.00
2 9 2017|0123456789|6.00 3.00
3 10 2017|0135792468|30.00 1.00
4 10 2017|0166778899|7.00 10.00
4 10 2017|0177001228|40.00 4.00
5 10 2017|0184040626|8.00 2.00
6 10 2017|0134567892|50.00 6.00
7 10 2017|0145678910|9.00 7.00
I tried using
while(inS >> Day>>Month >> Year >> ch >>hpNO >> ch >> c_Charges >> sms_charges )
but nothing seems to be worked .
Any suggestions to solve this problem?Thanks in advance.
void monthlyreport(char manager[])
{
SYSTEMTIME T;
GetSystemTime(&T);
int month, year; //userinput
char ch;//store delimitor
int count = 0;
double Totalcallcharges = 0;
double Totalsmscharges = 0;
double Totalcharges = 0;
int Day,Month, Year;//for textfile reading
char hpNO[11];
double c_Charges =0;
double sms_charges =0;
string Months[] = { "January","February","March","April","May","June","July","August","September","October","November","December" };
system("cls");
cout << "You choose : MONTHLY CHARGES REPORT ...";
cout << "\n\n Which month/year (mm yyyy)? ";
cin >> month;
cin >> year;
ifstream inS;
inS.open("Transaction.txt");
/*while (inS >> Day)
{
while (inS >> Month)
{
while (inS >> Year)
{
while (inS >> ch)
{
while (inS >> hpNO)
{
while (inS >> ch)
{
while (inS >> c_Charges)
{
while (inS >> sms_charges)
{
if (month == Month && year == Year)
{
Totalcallcharges += c_Charges;
}
if (month == Month && year == Year)
{
Totalsmscharges += sms_charges;
}
count++;
}
}
}
}
}
}
}
}
*/
while (!inS.eof()) correct answer
{
inS >> tranS.day >> tranS.month >> tranS.year >> ch;
inS.getline(tranS.phoneNO, 12, '|');
inS >> tranS.call_charges >> tranS.sms_charges;
transactions(&head, tranS);
if (tranS.month == month &&tranS.year == year)
{
tranS.Total_call_charges += tranS.call_charges;
tranS.Total_sms_charges += tranS.sms_charges;
}
count++;
}
Totalcharges = Totalcallcharges + Totalsmscharges;
inS.close();
system("cls");
cout << Month << year;
cout << endl << c_Charges;
cout << setw(50) << setfill('=') << " " << endl << endl;
cout << " T A R U C M O B I L E S D N B H D" << endl << endl;
cout << setfill(' ') << setw(30) << "Monthly Report - " << Months[month - 1] << " " << year << endl;
cout << "\nTotal Number of TARUCMOBILE users = " << count;
cout << "\n\nTotal Charges from Calls = RM" << setw(8) << setfill(' ') << Totalcallcharges << setprecision(2);
cout << "\nTotal Charges from SMS's = RM" << setw(8) << setfill(' ') << Totalsmscharges << setprecision(2);
cout << "\n" << setfill(' ') << setw(27) << " " << right << setw(12) << setfill('-') << "-" << endl;
cout << "TOTAL CHARGES (POSTPAID) = RM" << setw(8) << setfill(' ') << Totalcharges << setprecision(2);
cout << "\n" << setw(27) << setfill(' ') << " " << setw(12) << setfill('=') << "=" << endl;
cout << "*** E N D O F R E P O R T *** " << endl << endl;
cout << "Generated by" << endl;
cout << "______________" << endl;
cout << manager << "(Manager)" << endl;
cout << T.wDay << " " << Months[T.wMonth - 1] << " " << T.wYear << endl;
cout << endl << setw(50) << setfill('=') << " " << endl;
system("pause");
}