Link to home
Start Free TrialLog in
Avatar of andyw27
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 ?
Avatar of van_dy
van_dy

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") {                          //u were using asssignement, not the equality test operator
                    printf("You entered Yes\n");       }

               else if (cinema_visit == "n") {            
                    printf("You entered No\n");     }
                   
                   
         
 }
ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of andyw27

ASKER


Thanks that done the trick.
oh .. lol its "y" not 'y' :(