Okay so i've recently wrote a program calculating a utility bill. inputting the account number, name, type and usage..for example
{
validAccountNumber = false;
while (validAccountNumber == false)
{
cout << "Enter your 4-digit account number: ";
cin >> accountNumber;
if (accountNumber >= 1000 && accountNumber <= 9999) // sets the valid value of the account number
validAccountNumber = true;
else
{
cout << "Invalid account number. (Account numbers must be between 1000-9999)" << endl; //declares invalid values
exit(1);
}
i now want to change the input type to a data file.. and do the following
1. Ask the user to enter the data file name. Open the data file in read mode. If file opening is unsuccessful display appropriate message and exit the program.
2. Read how many records in the file. If there are no records in the file display an appropriate message and exit the program.
3. Read the next consumer information
4. Calculate utility bill for the consumer and display bill on the screen. After the current bill is displayed, display two blank lines and display the following message: Press [n/N] for next or [q/Q] to quit.
i have an understanding on how to make a simple input / output file program but converting a program i have already written is slightly confusing. any help would be apprecaited.
I think you should write your code here so that someone can help you.Otherwise [personally] I dont think that some will give you the complete code that suits your needs.
else
{
cout << "Invalid account number. (Account numbers must be between 1000-9999)" << endl; //declares invalid values
exit(1);
}
}
cin.ignore (80,'n');
cout << "Enter your account name: ";
cin.getline(accountName, 25);
validKwh = false;
while (validKwh == false)
{
cout << "Enter your electricity consumption in Kwh's: ";
cin >> Kwh;
if (Kwh >= 0)
validKwh = true;
else if (Kwh = 100)
validKwh = true;
}
validUnit = false;
while (validUnit == false)
{
cout << "Enter your water consumption in units: ";
cin >> unit;
if (unit >= 0)
validUnit = true;
else if (unit = 25)
validUnit = true;
}
cin.ignore (80, 'n');
validServiceCategory = false;
while (validServiceCategory == false)
{
cout << "Enter service category (R)esidential, (C)ommercial, or (I)ndustrial: ";
cin >> serviceCategory;
serviceCategory = toupper(serviceCategory);
if (serviceCategory == 'R' || serviceCategory == 'C' || serviceCategory == 'I') // || determines OR in the declaring of serviceCategory's
validServiceCategory = true;
else if (serviceCategory = 'R') //If an invalid value is entered, the category will be set to 'R' (residential)
validServiceCategory = true;
}
if (serviceCategory == 'R') // Calculating the electrical charges
if (Kwh <= 500)
electricCharge = Kwh * 0.050;
else
electricCharge = Kwh * 0.025;
if (serviceCategory == 'C')
if (Kwh <= 600)
electricCharge = Kwh * 0.080;
else
electricCharge = Kwh * 0.050;
if (serviceCategory == 'I')
if (Kwh <= 2500)
electricCharge = Kwh * 0.060;
else
electricCharge = Kwh * 0.015;
if (serviceCategory == 'R')
if (unit <= 30)
waterCharge = unit * 0.20;
else
waterCharge = unit * 0.10;
if (serviceCategory == 'C')
if (unit <= 30)
waterCharge = unit * 0.20;
else
waterCharge = unit * 0.15;
if (serviceCategory == 'I')
if (unit <= 5000)
waterCharge = unit * 0.10;
else
waterCharge = unit * 0.02;