andyw27
asked on
If then statement
How can I write the following programatically ?
Print "do you go to the cinema enter y for yes or no"
Then depending on your answer print either "yes you do" or "no you don't"
So far I have this (which does'nt work) as it always prints yes, regardless of what you input.
#include <stdio.h>
main()
{
char cinema_visit;
printf("Do you gp to the cinema ?\nEnter 'Y' for yes or 'N' for no: ");
scanf("%c",&cinema_visit);
if (cinema_visit = "y") {
printf("You entered Yes\n"); }
else if (cinema_visit = "n") {
printf("You entered No\n"); }
}
Any clues ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks that done the trick.
oh .. lol its "y" not 'y' :(
{
char cinema_visit;
printf("Do you gp to the cinema ?\nEnter 'Y' for yes or 'N' for no: ");
scanf("%c",&cinema_visit);
if (cinema_visit == "y") { //u were using asssignement, not the equality test operator
printf("You entered Yes\n"); }
else if (cinema_visit == "n") {
printf("You entered No\n"); }
}