If statements
Hey guys, sorry if you think this problem is too easy but i just can't find what's wrong with it. I am learning c# actually. In the solution, whenever i execute the program it jumps to the ELSE statement no matter what input i provide . If anyone could please help, THANK YOU !!
![No description](https://cdn.answeroverflow.com/1202416734683013230/Screenshot_9.png)
![No description](https://cdn.answeroverflow.com/1202416734980538398/Screenshot_8.png)
39 Replies
Are you using capital Y or N instead of lowercase ?
you gotta be typing something wrong because i recreated ur code and it works fine for me
No i used lowercase even so it doesnt work
It actually only executes the esle statement for some reason
For example insert 10 it does 10 * 125 when actually it should be doing the first IF statement
including the premium and discount
hold on i misread ill try it again
ok
its still working fine for me , i have not ran into any issues, using 10 and hitting y prints the first statement for me
wait rlly ?
What is the answer when you do so
when you hit 10 and "y:
1062.5
the problem is how you have ur code
this is how it works for me
int textbook;
char cover;
double rprice;
double fprice;
Console.WriteLine("Enter number of books");
textbook = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Do you want hardback? y/n");
cover = Convert.ToChar(Console.ReadLine());
rprice = textbook * 125;
if (cover == 'y' && textbook > 4)
{
double discount = 0.20; // 20% discount
double tax = 0.05; // 5% tax
fprice = rprice - (discount * rprice) + (tax * rprice);
Console.WriteLine(fprice);
}
The syntax looks the same though , just you assigned variables for discount and tax
$code
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
For longer snippets, use: https://paste.mod.gg/$codegif
what is this
and yes variables is how i got the progam to work, i was running into the same issue
nothing thats how they wanted me to post the code
You only have one if statement though and it will obviously only execute the said statement