Hello,
I have a couple of questions, both regarding IF.
I'm using Turboc to compile the program if its worth mentioning btw.
The first one- the assignment is this-
Someone rolls a dice, the score is determined like this-
if its an odd number, his score would be the dice * 2. (3*2=score=6)
if its an even number, his score would be the dice * 2 + 1 (4*2+1=score=9).
Now, I googled it many times and I got the same code,
Code:
int dice,total_score;
printf("enter your dice's score");
scanf("%d",&dice);
if(dice%2==0)
{
total_score=dice*2+1;
printf("you total score is: %d",total_score);
}
else
{
total_score=dice*2;
printf("your total score is: %d",total_score);
}
}
And everything works, I got my result as I expected, but would someone explain me how this works?
Especially that '%2' part, what does it do? didn't find an explanation for this one.
Second question-
I basically need to know how do I tell the program if X is bigger than 500, but is smaller than 1000 (500<X<1000), then do a certain thing.
An example-
if you buy something in a store that cost more than 500$, you get a 5% discount. but if you buy something for 1000$, you get 10% discount.
Obviously the 500<X<1000 didn't work, so I came here. x.x
hope everything is clear enough, thanks in advance,
Yuval.