DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: for, if,

  1. #1
    CoolMoDee Guest

    for, if,


    My Problem is this....i run this program, i run it with a rate of 10 dollars
    and hour with 22 hours of work for a total of $220. Well i have an if statment
    saying

    if(total > 201 && total < 321)

    it is supposed to go in to the 5% tax range, but it still goes into the 0%
    tax range. I dont know why it does this.. please look @ the code and tell
    me what is wrong..... Thanx A Lot CoolMoDee

    #include <iostream>

    int main()
    {
    int core, hours;
    double rate, rate1, ot, x, total, totaltax;
    cout<<"Please enter your rate an hour: \n";
    cin>>rate;
    cout<<"How many hours did you work?";
    cin>>hours;
    cout<<setiosflags(ios::fixed|ios::showpoint)<< setprecision(
    2 );
    if(hours >40)
    {
    x = hours - 40;
    rate1 = rate * 40;
    ot = x * (rate * 1.5);
    total = rate1 + ot;
    cout<<"You made " <<rate1 <<" at time and " <<ot
    <<" at time and a half." <<endl;
    cout<<"\n That is a total of " <<total <<" before
    taxes\n";
    }
    if(hours <= 40)
    {
    rate1 = rate * hours;
    cout<<"You made " <<rate1 <<" at time before taxes.";

    }
    double totaltaxf, totaltaxsevenfive, totaltaxten,
    totaltax1threefive, totaltaxonesix;
    if(total < 201)
    {
    cout<<"Taxes are 0% You get to
    take home " <<rate1 <<" .\n" <<endl;
    goto relog;
    }
    cout<<setiosflags(ios::fixed|ios::showpoint)<< setprecision(
    2 );
    if(total > 201 && total < 321)
    {
    totaltaxf = total - (total * .05);
    cout<<"Taxes are 5% " <<totaltaxf <<" .\n"
    <<endl;
    }
    return 0;
    }
    }

  2. #2
    Timo Peichl Guest

    Re: for, if,

    if (hours<=40) you never set total;

    CoolMoDee schrieb:
    >
    > My Problem is this....i run this program, i run it with a rate of 10 dollars
    > and hour with 22 hours of work for a total of $220. Well i have an if statment
    > saying
    >
    > if(total > 201 && total < 321)
    >
    > it is supposed to go in to the 5% tax range, but it still goes into the 0%
    > tax range. I dont know why it does this.. please look @ the code and tell
    > me what is wrong..... Thanx A Lot CoolMoDee
    >
    > #include <iostream>
    >
    > int main()
    > {
    > int core, hours;
    > double rate, rate1, ot, x, total, totaltax;
    > cout<<"Please enter your rate an hour: \n";
    > cin>>rate;
    > cout<<"How many hours did you work?";
    > cin>>hours;
    > cout<<setiosflags(ios::fixed|ios::showpoint)<< setprecision(
    > 2 );
    > if(hours >40)
    > {
    > x = hours - 40;
    > rate1 = rate * 40;
    > ot = x * (rate * 1.5);
    > total = rate1 + ot;
    > cout<<"You made " <<rate1 <<" at time and " <<ot
    > <<" at time and a half." <<endl;
    > cout<<"\n That is a total of " <<total <<" before
    > taxes\n";
    > }
    > if(hours <= 40)
    > {
    > rate1 = rate * hours;
    > cout<<"You made " <<rate1 <<" at time before taxes.";
    >
    > }
    > double totaltaxf, totaltaxsevenfive, totaltaxten,
    > totaltax1threefive, totaltaxonesix;
    > if(total < 201)
    > {
    > cout<<"Taxes are 0% You get to
    > take home " <<rate1 <<" .\n" <<endl;
    > goto relog;
    > }
    > cout<<setiosflags(ios::fixed|ios::showpoint)<< setprecision(
    > 2 );
    > if(total > 201 && total < 321)
    > {
    > totaltaxf = total - (total * .05);
    > cout<<"Taxes are 5% " <<totaltaxf <<" .\n"
    > <<endl;
    > }
    > return 0;
    > }
    > }


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center