Feb 25, 2016 at 5:51am UTC
Hallo.. I need to write this basic program. And I want it to read my input file from a txt file containing the following:
12345
R
790
29888
X
38116
P
375
982
My code is the following:
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
double charge1;
double charge2;
double charge;
int main()
{
ifstream imputFile;
int accountnumber;
char choice;
int minutes;
int daytimeM;
int eveningtimeM;
cout<<setprecision(2)<<fixed;
imputFile.open("/Users/lorenzopes/Documents/college/C++/example/printingcharge/printingcharge/billingdata.txt");
while(imputFile >> accountnumber)
{
imputFile >>accountnumber;
cout << "Enter your account number: ";
cout<<accountnumber;
imputFile>>choice;
cout<<"Enter your service code: (R/r-regular, P/p-premium): ";
cout<<choice;
switch (choice)
{
case 'R' :
case 'r' :
imputFile>>minutes;
cout<<"How many minutes were used this month? ";
cout<<minutes;
if(minutes<50)
{ charge=0;
cout<<"The monthly charge for account "<<accountnumber<<" is: $"<<charge<<endl;
}
else if(minutes>50)
{
charge=minutes*0.20;
cout<<"The monthly charge for account "<<accountnumber<<" is: $"<<charge<<endl;
}
break;
case 'P':
case 'p':
imputFile>>daytimeM;
cout<<"How many daytime minutes where used this month? ";
cout<<daytimeM;
if(daytimeM < 75)
charge1=0.0;
else if (daytimeM > 75)
charge1=(daytimeM-75)*0.10;
imputFile>>eveningtimeM;
cout<<"How many eveningtime minutes where used this month? ";
cout<<eveningtimeM;
if(eveningtimeM < 100)
charge2=0.00;
else if (eveningtimeM > 100)
charge2=(eveningtimeM-100)*0.05;
charge=25+(charge1+charge2);
cout<<"The monthly charge for account "<<accountnumber<<" is $" <<charge<<endl;
break;
default:
cout<<"** Invalid Service Code – Monthly Bill Not Calculated ** "<<endl;
}
}
}
Feb 25, 2016 at 6:56am UTC
> I need to write this basic program.
¿what should the program do?
> And I want it to read my input file from a txt file
OK, ¿so?
1 2 3 4 5 6 7
while (imputFile >> accountnumber)
{
//¿why so much whitespace?
imputFile >>accountnumber; //¿how many times will you read the account number?
Last edited on Feb 25, 2016 at 6:56am UTC