C Program: Kaun Banega Crorepati (KBC) (Who Will Become a Millionaire) Game – 2017
Crorepati (Who Will Become a Millionaire) is a game based on the television show kaun banega crorepati (Who Will Become a Millionaire) with the similar concept, it show questions on the output screen and ask the user to enter the correct answer number and is the answer is correct a message is appears on the screen showing the winning amount and the next question is presented else if the answer is wrong a message is displayed saying that the answer chosen by the user is not correct and hence the user loses.
We start by including the header files “stdio.h” and conio.h”.
void main()
{
int i,a[10],n=0;
printf("WELCOME TO THE GAME""KAUN BANEGA CROREPATHI""It contains10 QUESTIONS each carries 10 LAKHS");
After this, the program enters a for loop where the variable i=0 and it continues until the value of i is less than or equal to 10, after entering the for loop the program enters switch case statements where every case contains a question of the game crorepati.
for(i=1;i<=10;i++)
{
n=0;
switch(i)
{
User is presented with the question in each case with 4 options as according to the format of the game and is asked to enter the correct answer which is saved in variable ‘n’ and then checked is the given answer is correct or not.
case 1:
printf("In what direction muslim pray 1.East 2.South 3.Nearby Mosque's direction 4.Mecca's direction ");
scanf("%d",&n);
if(n==4)
{
printf("You have entered the correct answer Now you have won Rs.%d00000 Your Next Question is ",i);
}
else
{
printf(" You have entered the wrong answer Better Luck Next Time You have earned Rs.%d00000",i-1);
i=11;
}
break;
If the answer is correct break statement is executed and the loop runs again and this time the value of i is equal to 2 which takes it to second case and similary to third and rest.
But if the chosen answer is not correct then the value of ‘i’ becomes 11 and then the break statement is executed which makes the for loop run again but this time the value of ‘i’ becomes 12 which is not present in any case and hence the default case is executed which makes the program exit the output screen.
default:
break;
}
}
getch();
}
Download Source Code – C Program Kaun Banega Crorepati KBC Game – 2017 -CodeWithC
[sociallocker]Download Source Code – C Program Kaun Banega Crorepati KBC Game – 2017 -CodeWithC
Password – codewithc.com
[/sociallocker]