int main()
{
constint bfee_1=10; //monthly charge
constint bfee_2=15; //addon for balance <$400
constdouble fee_3=.10; //check fee for <20 checks
constdouble fee_4=.08; //check fee for 21-39 checks
constdouble fee_5=.06; //check fee for 40-59 checks
constdouble fee_6=.04; //check fee for >=60 checks
double AcctBal; //Account Balance before any fees
int checks; //number of checks written
double servfee_1=bfee_1+bfee_2+(checks*fee_3); //total monthly fee for account balance under $400 and <20 checks written
double servfee_2=bfee_1+bfee_2+(checks*fee_4); //total monthly fee for account balance under $400 and 20-39 checks written
double servfee_3=bfee_1+bfee_2+(checks*fee_5); //total monthly fee for account balance under $400 and 40-59 checks written
double servfee_4=bfee_1+bfee_2+(checks*fee_6); //total monthly fee for account balance under $400 and >=60 checks written
cout <<"Please enter you current account balance\n";
cin >> AcctBal;
if (AcctBal < 0)
cout<<"Warning! You are overdrawn. Please Deposit money\n";
elseif (AcctBal < 400)
cout<<"Please entry number of checks written this month\n";
cin>>checks;
{
if (checks<20)
cout <<"Your service fee this month is"<<servfee_1<<"\n";
elseif (20<=checks && checks<39)
cout <<"Your service fee this month is"<<servfee_2<<"\n";
elseif (40<=checks && checks<60)
cout <<"Your service fee this month is"<<servfee_3<<"\n";
else (checks>=60);
cout <<"Your service fee this month is"<<servfee_4<<"\n";
}
else (AcctBal >= 400);
cout<<"Please entry number of checks written this month\n";
cin>>checks;
{
if (checks<20)
cout<<"Your service fee this month is"<<servfee_1-bfee_2<<"\n";
elseif (20<=checks && checks<39)
cout<<"Your service fee this month is"<<servfee_2-bfee_2<<"\n";
elseif (40<=checks && checks<60)
cout<<"Your service fee this month is"<<servfee_3-bfee_2<<"\n";
else (checks>=60);
cout<<"Your service fee this month is"<<servfee_4-bfee_2<<"\n";
}
return 0;
}
#include <iostream>
usingnamespace std;
int main()
{
constint bfee_1=10; //monthly charge
constint bfee_2=15; //addon for balance <$400
constdouble fee_3=.10; //check fee for <20 checks
constdouble fee_4=.08; //check fee for 21-39 checks
constdouble fee_5=.06; //check fee for 40-59 checks
constdouble fee_6=.04; //check fee for >=60 checks
double AcctBal; //Account Balance before any fees
int checks; //number of checks written
double servfee_1=bfee_1+bfee_2+(checks*fee_3); //total monthly fee for account balance under $400 and <20 checks written
double servfee_2=bfee_1+bfee_2+(checks*fee_4); //total monthly fee for account balance under $400 and 20-39 checks written
double servfee_3=bfee_1+bfee_2+(checks*fee_5); //total monthly fee for account balance under $400 and 40-59 checks written
double servfee_4=bfee_1+bfee_2+(checks*fee_6); //total monthly fee for account balance under $400 and >=60 checks written
cout <<"Please enter you current account balance\n";
cin >> AcctBal;
{
if (AcctBal < 0)
cout<<"Warning! You are overdrawn. Please Deposit money\n";
elseif (AcctBal < 400)
cout<<"Please entry number of checks written this month\n";
cin>>checks;
{
if (checks<20)
cout <<"Your service fee this month is"<<servfee_1<<"\n";
elseif (20<=checks && checks<39)
cout <<"Your service fee this month is"<<servfee_2<<"\n";
elseif (40<=checks && checks<60)
cout <<"Your service fee this month is"<<servfee_3<<"\n";
else (checks>=60);
cout <<"Your service fee this month is"<<servfee_4<<"\n";
}
else (AcctBal>=400);
cout<<"Please entry number of checks written this month\n";
cin>>checks;
{
if (checks<20)
cout<<"Your service fee this month is"<<servfee_1-bfee_2<<"\n";
elseif (20<=checks && checks<39)
cout<<"Your service fee this month is"<<servfee_2-bfee_2<<"\n";
elseif (40<=checks && checks<60)
cout<<"Your service fee this month is"<<servfee_3-bfee_2<<"\n";
else (checks>=60);
cout<<"Your service fee this month is"<<servfee_4-bfee_2<<"\n";
}
}
return 0;
}
Line 28 will only do line 29, and then 30 to the end will run every time, regardless. You need to use the curly braces to force the else-if to do everything from lines 29 to 41. The else on line 42 is illegal because currently, it is right after another else statement and not an if/else-if.
I am trying again from start. I get bool error but it starts to run anyway. If I enter a neg number it still continues instead of bumping to end?? I also have other looping errors. Please help.
#include <iostream>
usingnamespace std;
int main()
{
constint bfee_1=10; //monthly charge
constint bfee_2=15; //addon for balance <$400
double fee_3=.10; //check fee for <20 checks
double fee_4=.08; //check fee for 21-39 checks
double fee_5=.06; //check fee for 40-59 checks
double fee_6=.04; //check fee for >=60 checks
double AcctBal; //Account Balance before any fees
int checks; //number of checks written
double servfee_1=bfee_1+bfee_2+(checks*fee_3); //total monthly fee for account balance under $400 and <20 checks written
double servfee_2=bfee_1+bfee_2+(checks*fee_4); //total monthly fee for account balance under $400 and 20-39 checks written
double servfee_3=bfee_1+bfee_2+(checks*fee_5); //total monthly fee for account balance under $400 and 40-59 checks written
double servfee_4=bfee_1+bfee_2+(checks*fee_6); //total monthly fee for account balance under $400 and >=60 checks written
cout <<"Please enter you current account balance\n";
cin >> AcctBal;
if (AcctBal < 0)
{
cout<<"Warning! You are overdrawn. Please Deposit money\n";
}
if (0>=AcctBal <400)
{
cout<<"Please entry number of checks written this month\n";
cin>>checks;
if (checks<20)
cout <<"Your service fee this month is"<<servfee_1<<"\n";
elseif (20<=checks<39)
cout <<"Your service fee this month is"<<servfee_2<<"\n";
elseif (40<=checks<60)
cout <<"Your service fee this month is"<<servfee_3<<"\n";
else (checks>=60);
cout <<"Your service fee this month is"<<servfee_4<<"\n";
}
if (AcctBal >= 400)
{
cout<<"Please entry number of checks written this month\n";
cin>>checks;
if (checks<20)
cout<<"Your service fee this month is"<<servfee_1-bfee_2<<"\n";
elseif (20<=checks<39)
cout<<"Your service fee this month is"<<servfee_2-bfee_2<<"\n";
elseif (40<=checks<60)
cout<<"Your service fee this month is"<<servfee_3-bfee_2<<"\n";
else (checks>=60);
cout<<"Your service fee this month is"<<servfee_4-bfee_2<<"\n";
}
return 0;
}
Look at line 30. It doesn't do what you think it does, which is why you have an error. The expression 0>=AcctBal <400 first checks if 0 is greater or equal to AcctBal; this operation returns a boolean (bool). Then, you try to see if that boolean is less than 400...wait what? How can a boolean, being true or false, be less than 400? It can't, which is why you have an error from the compiler. I think what you meant to do was this: if(AcctBal <= 0 && AcctBal < 400)
However, that is clearly not what you wanted...I think you really wanted this: if(AcctBal >= 0 && AcctBal < 400)
I have made some progress but it says variable checks not initialized. Isn't it initialized in lines 33 and 48? if I set variable checks=0 it doesnt calculate properly