Welcome fellow students, register yourself and dive into asking questions, giving answers and helping the community learn with you.

help me out , this code doesn't seems to work (I've just started to learn C)

0 votes
asked Feb 2, 2018 in CS50 by AnandPharmacist (120 points)
#include <stdio.h>

int main(void)

{

char name[20], ans;

int point = 0;

 

//intro

printf("********************************************\n");

printf("********************************************\n");

printf("********    Let's play K B C   *************\n");

printf("********************************************\n");

printf("********************************************\n");

printf("                                            \n");

printf("                                            \n");

printf("                                            \n");

 

//rules

printf("Here are the rules\n");

printf("You will be given a question with 4 options\n");

printf("choose one answer\n");

printf("correct answer gives you 10 points, wrong answer ends the game\n");

printf("                                            \n");

printf("                                            \n");

 

//user input name

printf("to begin enter your name and press enter\n");

scanf("%s",name);

 

//first question

printf("                                            \n");

printf("                                            \n");

printf("Question 1\n");

printf("What is the highest peak in the world ?\n");

printf("A : Mt everest                  B : Mt k2\n");

printf("C : Kanchejunga                 D : Kilimanjaro\n");

 

// answer input

printf("enter your answer: \n");

scanf("%c", &ans);

 

//logic for correct answer

if(ans=='a' || ans=='A')

{

printf("Correct answer %s\n", name);

point += 10;

printf("your score is %i\n", point);

}

 

//logic for incorrect anwer

else

{

printf("Wrong answer, sorry you lose %s\n", name);

printf("your score is %i\n", point);

return 0;

}

 

printf("Question 2\n");

printf("What is the longest river ?\n");

printf("A : Nile                   B : Ganga\n");

printf("C : Yamuna                 D : Amamzon\n");

 

if(ans=='a' || ans=='A')

{

printf("Correct answer %s\n", name);

point += 10;

printf("your score is %i\n", point);

}

else

{

printf("Wrong answer, sorry you lose %s\n", name);

printf("your score is %i\n", point);

return 0;

}

 

printf("Question 2\n");

printf("Who was the first person to land on moon?\n");

printf("A : Yuri Gagrin                 B : Neil armstrong\n");

printf("C : Buzz Aldrin                 D : all of these\n");

 

if(ans=='b' || ans=='B')

{

printf("Correct answer %s\n", name);

point += 10;

printf("your score is %i\n", point);

}

else

{

printf("Wrong answer, sorry you lose %s \n", name);

printf("your score is %i\n", point);

return 0;

}

return 0;

}

Please log in or register to answer this question.

Welcome to CS50xHelpers Q&A, where you can ask questions and receive answers from other members of the community.

192 questions

248 answers

217 comments

3,675 users

3 Online
0 Member And 3 Guest
...