Thread: Problem 1

  1. #1
    Registered User
    Join Date
    Feb 2016
    Posts
    6

    Problem 1

    Hi i recently made a really small quiz just as an exercise and i have an error that i don understand how can i correct, if you guys tell me how i am supposed to correct it ! i know that is related to the scanf but cant find why!

    Code:
    
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
        char decision[50];
        char question1[50];
        char question2[50];
        char question3[50];
        printf("Welcome\n\aThis game was designed to be an example of a simple game!\n");
        printf("The game will have 3 questions. If you want to play say (yes).\n");
    
        scanf(" %s", decision);
    
        if(strcmp(decision,"yes") == 0){
    
            printf("Thank you for your time, goodluck!\n");
            printf("Question 1.\n Who was the winner of Liga Nos in 2014/2015\n");
            printf("a)Porto b)Benfica c)Sporting d)Braga\n");
            scnaf(" %s", question1);
    
            if(strcmp(question1,"b") == 0){
    
                printf("Good job.\a\n Who won the ballon d'ore in 2016?\n");
                printf("a)Ronaldo b)Neur c)Neymar d)Messi");
                scnaf(" %s", question2);
    
                if(strcmp(question2,"d") == 0){
    
                    printf("Good job.\a\n Last question. Who won puskas in 2016?\n");
                    printf("a)Alessandro Florenzi b)Leo Messi");
                    scnaf(" %s", question3);
    
                    if(strcmp(question3,"b") == 0){
                        printf("\nWell done you Won!");
                    }else{
                        printf("Sorry you are wrong! Maybe next time!\a\n");
    
                    }
    
    
    
                }else{
                    printf("Sorry you are wrong! Maybe next time!\a\n");
                }
    
    
            }else{
                printf("Sorry you are wrong! Maybe next time!\a\n");
    
            }
    
    
        }else{
            printf("Thank you anyway!\n\a");
        }
        return 0;
    }
    
    ty guys ^^

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,662
    > scnaf(" %s", question3);
    Perhaps it's because you spelt scanf wrong.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User naaissus's Avatar
    Join Date
    Jan 2016
    Location
    Balkan
    Posts
    23
    Also you need to include string.h to be able to use strcmp.

    To help you remember -> scan formatted -> scanf

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 02-09-2014, 06:46 PM
  2. Problem passing argument into function, basic problem
    By tsdad in forum C++ Programming
    Replies: 7
    Last Post: 05-22-2013, 12:09 PM
  3. Replies: 2
    Last Post: 01-06-2013, 07:49 AM
  4. Replies: 1
    Last Post: 12-07-2012, 10:00 AM
  5. Replies: 4
    Last Post: 10-16-2008, 07:30 PM

Tags for this Thread