Mar 12, 2012 at 4:07pm UTC
hidy ho all.
I'm having a little trouble with a program I'm writing for school. Before we go any further, I'm not looking for easy answers or someone to write the program for me.
now that we got that out of the way one of the inputs is giving me a weird answer.
the program is:
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
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
double inp;
cout << "Please type the amount ordered" << endl;
cin >> inp;
if (inp >0 && inp <=9){
cout << "The Cost is " << inp*99 << endl;}
if (inp >10 && inp <=19);{
cout << "The Cost is " << inp*99*(1 - 0.1) << endl;}
if (inp >20 && inp <=29){
cout << "The Cost is " << inp*99*(1 - 0.2) << endl;}
if (inp >30 && inp <=39){
cout << "The Cost is " << inp*99*(1 - 0.3) << endl;}
if (inp >40 && inp <=59){
cout << "The Cost is " << inp*99*(1 - 0.4) << endl;}
if (inp >60 && inp <=99){
cout << "The Cost is " << inp*99*(1 - 0.5) << endl;}
if (inp >100 && inp <=200){
cout << "The Cost is " << inp*99*(1 - 0.6) << endl;}
if (inp >200){
cout << "Invalid input, input greater then 200" << endl;}
return 0;
}
when I input 30 it gives me a blank output:
Please input the amount ordered
30
press any key to end the program...
why is it doing that? and how can i fix it?
edit: it does compile just fine, no errors
Last edited on Mar 12, 2012 at 8:11pm UTC
Mar 12, 2012 at 4:09pm UTC
Check the conditions for your third if and your fourth if. Do you see any values for which they wouldn't be true?
The same goes for all your ifs. :(
-Albatross
Last edited on Mar 12, 2012 at 4:09pm UTC
Mar 12, 2012 at 8:10pm UTC
I'm sorry, i'm not sure that i see the problem you guys are.
with:
1 2 3
if (inp >30 && inp <=39){
cout << "The Cost is " << inp*99*(1 - 0.3) << endl;
}
doesn't 30 fall into that area? or should it say something like:
1 2 3
if (inp >=30 && inp <=39){
cout << "The Cost is " << inp*99*(1 - 0.3) << endl;
}
also, srry. first post, i think i found the code button
Last edited on Mar 12, 2012 at 8:12pm UTC
Mar 12, 2012 at 8:19pm UTC
Is 30 greater than 30?
(no, it's not, so you need it to be if (inp >= 30 && inp <= 39)
, and similarly for the other if
s)