If statement

So I dont know what's wrong with my code. I have to do this task for school:
If you are buying more than 5 things, butless than 10 - you get 5% off. If you are buying 10 and more things you get 10% off.
Write a program, which would count how much you need to pay for products.
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
  int k;
float x;

cin>>x;
cin>>k;

if(5<k<10){


    x=(x-x*5/100)*k;
    cout<<x;

}

else if(k>10){


    x=(x-10*x/100)*k;
    cout<<x;
    }
    else{
cout<<"no"<<endl;

}
    return 0;

}



THANKS!!!
Last edited on
Take a look at line 7:

if(5<k<10){ It is not doing what you think is doing. You need to use one of the logical operators such as && ,||, ! .
Read up on those
The && operator is known as the logical AND operator. It takes two expressions as operands and creates an expression that is true only when both sub-expressions are true. Example:
1
2
if (temperature < 20 && minutes > 12)
cout << "The temperature is in the danger zone.";


The || operator is known as the logical OR operator. It takes two expressions as operands and creates an expression that is true when either of the sub-expressions are true. Example:

1
2
if (temperature < 20 || temperature > 100)
cout << "The temperature is in the danger zone.";


The ! operator performs a logical NOT operation. It takes an operand and reverses its truth or falsehood. In other words, if the expression is true, the ! operator returns false, and if the expression is false, it returns true. Example:

1
2
if (!(temperature > 100))
cout << "You are below the maximum temperature.\n";



I hope it gives you an idea. Good luck!



It helped!
Topic archived. No new replies allowed.