This is an assignment for class. I have everything right up to the point where the total and savings (if any) part came up. I only want certain messages to come up if certain hours are put in. For some reason it goes straight to the first option and outputs that message.
As you can see, I put that section as if, then if else's. I tried using only if and things were a lot worse, showing multiple unwanted messages and different total.
I would really appreciate help with this. I'm completely stumped.
if (pack == 'b' || pack == 'B' && hours > 25)
{
over = hours - 20;
total = total + over;
cout<<setprecision(2)<<fixed;
cout<<"The total amount due is: $"<<total<<endl;
cout<<"You could have saved $"<<over*2<<" by selecting package C."<<endl;
}
elseif (pack == 'b' || pack == 'B' && hours > 20 && hours < 25)
{
over = hours - 20;
total = total + over;
cout<<setprecision(2)<<fixed;
cout<<"The total amount due is: $"<<total<<endl;
}
elseif (pack == 'b' || pack == 'B' && hours <= 20)
{
cout<<setprecision(2)<<fixed;
cout<<"The total amount due is: $"<<total<<endl;
}
if (pack == 'a' || pack == 'A' && hours > 15)
{
over = hours - 10;
total = total + (over * 2);
cout<<setprecision(2)<<fixed;
cout<<"The total amount due is: $"<<total<<endl;
cout<<"You could have saved $"<<over<<" by selecting package B."<<endl;
cout<<"You could have saved $"<<over*2<<" by selecting package C."<<endl;
}
elseif (pack == 'a' || pack == 'A' && hours == 14)
{
over = hours - 10;
total = total + (over * 2);
cout<<setprecision(2)<<fixed;
cout<<"The total amount due is: $"<<total<<endl;
cout<<"You could have saved $"<<over<<" by selecting package B."<<endl;
}
elseif (pack == 'a' || pack == 'A' && hours > 10 && hours < 13)
{
over = hours - 10;
total = total + (over * 2);
cout<<setprecision(2)<<fixed;
cout<<"The total amount due is: $"<<total<<endl;
}
elseif (pack == 'a' || pack == 'A' && hours <= 10)
{
cout<<setprecision(2)<<fixed;
cout<<"The total amount due is: $"<<total<<endl;
}
}
system ("pause");
return 0;
}
#include <iostream>
#include <iomanip>
usingnamespace std;
int main()
{
double number = 12.32656;
cout << number << endl;
cout << setprecision(2) << fixed;
cout << number << endl;
int cc;
do
{
cout << "Enter number from 1 to 4: ";
cin >> cc;
if (cc == 1)
{
cout << 45.2355654;
}
elseif (cc == 2)
{
cout << 78.32654;
}
elseif (cc == 3)
{
//if you enter 3 precision will be 3.
cout << setprecision(3) << fixed;
cout << 12.365654;
}
elseif (cc == 4)
{
cout << 6.245756;
}
cout << endl;
}
while (cc > 0);
return 0;
}
output
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
12.3266
12.33
Enter number from 1 to 4: 1
45.24
Enter number from 1 to 4: 2
78.33
Enter number from 1 to 4: 4
6.25
Enter number from 1 to 4: 3
12.366
Enter number from 1 to 4: 1
45.236
Enter number from 1 to 4: 2
78.327
Enter number from 1 to 4: 4
6.246
Enter number from 1 to 4: