hello friends,
I am trying to make a quiz game
but after you press 'S" and register your name
then when i press Y so that the quiz start its going back to main menu
but when i press shift y in my keyboard the quiz starts
but even though i select right answer it shows you are wrong?
but when i select shift and the correct choice it works
so somehow toupper() function not working ?
here is my code just look into main function
Code:
#include <stdio.h>#include<conio.h>
#include<ctype.h>
#include <stdlib.h>
#include<string.h>
void show_record();
void reset_score();
void help();
int main(){
int countr,r,rl,count,i,n;
float score;
char choice;
char playername[20];
mainhome:
system("cls");
printf("\t\t\tC PROGRAM QUIZ GAME\n");
printf("\n\t\t_____________________________________________");
printf("\n\t\t\t WELCOME ");
printf("\n\t\t\t to ");
printf("\n\t\t\t THE GAME ");
printf("\n\t\t_____________________________________________");
printf("\n\t\t_____________________________________________");
printf("\n\t\t BECOME A MILLIONAIRE!!!!!!!!!!! ");
printf("\n\t\t_____________________________________________");
printf("\n\t\t_____________________________________________");
printf("\n\t\t > Press S to start the game ");
printf("\n\t\t > Press V to view the highest score ");
printf("\n\t\t > Press R to reset score ");
printf("\n\t\t > Press H for help ");
printf("\n\t\t > Press Q to quit ");
printf("\n\t\t_____________________________________________");
choice = toupper(getch());
if (choice=='V'){
show_record();
goto mainhome;
}else if (choice=='H') {
help();
getch();
goto mainhome;
} else if(choice=='R'){
reset_score();
getch();
goto mainhome;
}else if(choice == 'Q'){
exit(1);
}else if(choice =='S'){
system("cls");
printf("\n\n\n\n\n\n\n\n\t\t\tRegister your name:");
gets(playername);
system("cls");
printf("\n---------------------Welcome %s to C Quiz Game-----------------------------",playername);
printf("\n\n\t\tHere are some tips you might wanna know before playing:");
printf(" -------------------------------------------------------------------");
printf("\n\n >> There are two rounds in this Quiz game,WARMUP ROUND & CHALLENGE ROUND");
printf("\n\n >> In Warm up Round you will be asked total 3 questions to test your");
printf("\n general knowledge.You are eligible to play the game if you give at least 2");
printf("\n right answers ,otherwise you can't proceed further to the Challenge round");
printf("\n\n >> Your game starts at Challenge Round .In this round you will be asked a");
printf("\n total of 10 questions,Each right answer will be awarded $100,000!");
printf("\n By this way you can win up to ONE MILLION CASH PRIZE !!!!!.........");
printf("\n\n >> You will be given 4 options and you have to press A , B ,C or D for the");
printf("\n right option.");
printf("\n\n >> You will be asked questions continuously till right answers are given");
printf("\n\n >> No negative marking for wrong answers");
printf("\n\n\t!!!!!!!!!!!!!!!!!!!!!!!!ALL THE BEST !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ");
printf("\n\n\n Press Y to start new game!\n");
printf("\n Press any other key to return to the main menu");
if(toupper(getch()=='Y')){
goto home;
}else{
goto mainhome;
system("cls");
}
home:
system("cls");
count = 0;
for(i=0;i<=3;i++){
system("cls");
rl = i;
switch(rl){
case 1:
printf("\n\nWhich of the following is Palindrome number?");
printf("\n\nA.42042\t\tB.101010\n\nC.23232\t\tD.01234");
if(toupper(getch()=='C')){
printf("\nCorrect!!!");
count++;
getch();
break;
} else {
printf("\nWrong!!! .The correct answer is C.23232");
getch();
break;
}
case 2:
printf("\n\nThe Country with highest environmental performance index is...?");
printf("\n\nA.France\t\tB.Denmark\n\nC.Switzerland\t\tD.Finland");
if(toupper(getch()=='C')){
printf("\nCorrect!!!");
count++;
getch();
break;
} else {
printf("\nWrong!!! .The correct answer is C.Switzerland");
getch();
break;
}
case 3:
printf("\n\nWhich animal laughs like human being?");
printf("\n\nA.Polar Bear\t\tB.Hyena\n\nC.Donkey\t\tD.Chimpanzee");
if(toupper(getch()=='B')){
printf("\nCorrect!!!");
count++;
getch();
break;
} else {
printf("\nWrong!!! .The correct answer is B.Hyena");
getch();
break;
}
case 4:
printf("\n\nWho was awarded the youngest player award in Fifa World Cup 2006?");
printf("\n\nA.Wayne Rooney\t\tB.Lucas Podolski\n\nC.Lionel Messi\t\tD.Christiano Ronaldo");
if(toupper(getch()=='B')){
printf("\nCorrect!!!");
count++;
getch();
break;
} else {
printf("\nWrong!!! .The correct answer is B.Lucas Podolski");
getch();
break;
}
case 5:
printf("\n\nWhich is the third highest mountain in the world?");
printf("\n\nA.Mt. K2\t\tB.Mt. Kanchanjungha\n\nC.Mt. Makalu\t\tD.Mt. Kilimanjaro");
if(toupper(getch()=='B')){
printf("\nCorrect!!!");
count++;
getch();
break;
} else {
printf("\nWrong!!! .The correct answer is B.Mt. Kanchanjungha");
getch();
break;
}
case 6:
printf("\n\nWhat is the group of frogs known as?");
printf("\n\nA.A Traffic\t\tB.A Toddler\n\nC.A Police\t\tD.An Army");
if(toupper(getch()=='D')){
printf("\nCorrect!!!");
count++;
getch();
break;
} else {
printf("\nWrong!!! .The correct answer is D.An Army");
getch();
break;
}
}
}
if(count>=2){
printf("\nyay you win");
}else{
printf("\nyou lost");
}
}
return 0;
}
void show_record(){
system("cls");
char name[20];
float scr;
FILE *f;
f = fopen("score.txt","r");
fscanf(f,"%s%f",&name,&scr);
printf("\n\n\n\t***********************************************************");
printf("\n\n\n\t %s has scored the Highest Score %0.2f",name,scr);
printf("\n\n\n\t***********************************************************");
fclose(f);
getch();
}
void reset_score(){
system("cls");
float sc;
char nm[20];
FILE *f;
fopen("score.txt","r+");
fscanf(f,"%s%f",&nm,&sc);
sc = 0;
fprintf(f,"%s%,.2f",nm,sc);
fclose(f);
}
void help(){
system("cls");
printf("\n\n HELP");
printf("\n------------------------------------------------------------------------------------");
printf("\n..............................C Program Quiz Game.......................");
printf("\n >> There are two rounds in the game, WARMUP ROUND & CHALLENGE ROUND");
printf("\n >> In warmup round you will be asked 3 questions to test your general");
printf("\n knowledge .You will be eligible to play the game if you give at least 2");
printf("\n right answers otherwise you can't play the Game................");
printf("\n >> Your game starts with the CHALLENGE ROUND. In this round you will be asked");
printf("\n total 10 questions ,each right answer will be awarded $100,000.");
printf("\n By this way you win up to 1million cash prize in USD.................");
printf("\n >> You will be given 4 options and you have to press A ,B ,C or D for the");
printf("\n right option.");
printf("\n >> You will be asked questions continuously if you keep giving the right answers");
printf("\n >> No negative marking for wrong answers");
printf("\n\n\t*****************************BEST OF LUCK****************************************");
printf("\n\n\t******************C PROGRAM DEVELOPED BY CODEWITHC *********************************");
}