Dec 4, 2013 at 3:36am UTC
I am trying to get this program running and calculate more than one bill. I did everything but whenever I am done with one bill and trying to say "Y" for another bill to process.
It clears screen and pause but would never let me do more bill calculation.
Any Help please
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
//complier directives
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<string>
using namespace std;
// CONSTANTS
const double RESIDENTIAL_LINE_FEE = 22.09; //Residential line fee
const double COMMERCIAL_LINE_FEE = 22.09; //Commercial line fee
const double INDUSTRIAL_LINE_FEE = 18.41; //Industrial line fee
//function prototypes
double CalcResidential(float GalUsedf);
double CalcCommercial(float GalUsedf);
double CalcIndustrial(float GalUsedf);
int main()
{
//local identifiers
string Name, AccountType;
int AccountNum;
float GalUsed;
double total;
char choice, Another;
cout<<setw(61)<<"Welcome to the Onondaga Water Bill Calculator" <<endl;
cout<<endl;
cout<<"Please enter your account name:<termintate with # sign>\t" ;
getline(cin, Name, '#' );
cout<<"Please enter your 5 digit account number: \t" ;
cin>>AccountNum;
cout<<"Please enter the number of gallons used this quarter: \t" ;
cin>>GalUsed;
cout<<"Please choose from the following account types: \n" ;
cout<<endl;
cout<<setw(29)<<" H for Residential" <<endl;
cout<<endl;
cout<<setw(29)<<" C for Commercial " <<endl;
cout<<endl;
cout<<setw(29)<<" I for Industrial " <<endl;
cout<<endl;
cin>>choice;
cout<<endl;
switch (choice)
{
case 'H' :
case 'h' :
AccountType = "Residential" ;
total = CalcResidential(GalUsed);
break ;
case 'C' :
case 'c' :
AccountType = "Commercial" ;
total = CalcCommercial(GalUsed);
break ;
case 'I' :
case 'i' :
AccountType = "Industrial" ;
total = CalcIndustrial(GalUsed);
break ;
default :
cout << "Error. Please ask for assistance." ;
}
cout << "Onondaga County Water Bill" << endl;
cout<<endl;
cout << "Account Name: " <<Name<<endl;
cout << "Account Number: " <<setfill('0' )<<setw(5)<<AccountNum<<setfill(' ' );
cout << endl;
cout << fixed << showpoint << setprecision(2);
cout << "Account Type: " <<AccountType<<endl;
cout << "Gallons Used: " <<GalUsed<<endl;
cout << "Ammount Due: $" <<total<<endl;
cout<<"Do you have another account to process? <Y or N>" ;
cin>>Another;
if ((Another=='Y' )||(Another=='y' ))
{
system("PAUSE" );
system("CLS" );
}while ((Another=='Y' )||(Another=='y' ));
return main();
}//end of main
double CalcResidential(float GalUsedf)
{
double cost;
cost = RESIDENTIAL_LINE_FEE;
if (GalUsedf <= 0)
cost = 0.0;
else
{
if (GalUsedf <= 10000)
cost += (GalUsedf / 1000) * 2.42;
else
if (GalUsedf <= 23000)
{
cost += (10000 / 1000) * 2.42;
cost += ((GalUsedf - 10000) / 1000) * 3.22;
}
else
{
cost += (10000 / 1000) * 2.42;
cost += (13000 / 1000) * 3.22;
cost += ((GalUsedf - 23000) / 1000) * 4.03;
}
}
return cost;
}
double CalcCommercial(float GalUsedf)
{
double cost;
cost = COMMERCIAL_LINE_FEE;
if (GalUsedf <= 0)
cost = 0.0;
else
cost += (GalUsedf/1000) * 2.65;
}
double CalcIndustrial(float GalUsedf)
{
double cost;
cost = INDUSTRIAL_LINE_FEE;
if (GalUsedf <= 0)
cost = 0.0;
else
{
if (GalUsedf <= 200000)
cost += (GalUsedf / 1000) * 2.16;
else
if (GalUsedf <= 2700000)
{
cost += (200000 / 1000) * 2.16;
cost += ((GalUsedf - 200000) / 1000) * 1.73;
}
else
{
cost += (200000 / 1000) * 2.16;
cost += (2500000 / 1000) * 1.73;
cost += ((GalUsedf - 2700000) / 1000) * 4.03;
}
}
return cost;
}//end of function
Last edited on Dec 5, 2013 at 8:59pm UTC
Dec 5, 2013 at 4:44am UTC
could any body help me please fix my program and make it run please pleasssssseeee
Dec 5, 2013 at 4:51pm UTC
did i put prompt for Another in right place.
i mean when i try to run it, it runs it and also ask for another.
after i press y or Y for yes, it will pause and clear the screen but it will do nothing after that. So i am missing something there and I could not figure it out. Any more help please
Dec 5, 2013 at 5:49pm UTC
Please use code tags when posting code. The more readable your post is, the more likely people are to take the time to read it and help.
Dec 5, 2013 at 9:00pm UTC
Sorry about that. I just coded it. Hoping for some help here.
Thabks MikeyBoy. I really appreciate that.
Dec 5, 2013 at 9:21pm UTC
Smiley Wolf is incorrect. The condition he proposes will always be true (since Another can't be both 'y' and 'Y' at the same time, one of those conditions will pass and LOGICAL OR will yield true).
@evan1991 look at the syntax for a do-while loop. You have a while in your code, but it neither opens a new loop that does something or ends an existing 'do'. Essentially it is an empty while loop that never terminates.
I would suggest on line 26 you say
do {
and change the bottom of your main to look like this:
1 2 3 4 5 6
if ((Another=='Y' )||(Another=='y' ))
{
system("PAUSE" );
system("CLS" );
} //close the if block first
} while ((Another=='Y' )||(Another=='y' )); //then close the do while block
Last edited on Dec 5, 2013 at 9:23pm UTC
Dec 6, 2013 at 2:40am UTC
it didn't work.
I don't know if I put prompt for another in wrong place or something. But its not working though.
Thanks for your help though