题目设置
总共15道题,每个题四个选项,只有一个正确答案。
求助热线
三个求助选项,50/50:去掉两个错误答案,call a friend:随机得到一个答案,ask the audience:得到观众关于四个选项的投票概率。
奖励与惩罚
每个题目都有相应的奖励金额,答对一题奖金池都会增加,在1-5题答错,则失去所有奖励,6-10题答错,则可以带走5000,11-15题答错则可以带走50000.
具体代码
// An highlighted block
#include "pch.h"
#include <iostream>
#include<time.h>
#include <windows.h>
#include <stdlib.h>
void gotoxy(int x, int y)
{
COORD coord;
coord.X = y;
coord.Y = x;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
/*void color(short x)
{
if (x >= 0 && x <= 15)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), x);
}
else
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
}
}*/
struct game
{
int questionNumber;
int gameReward;
char questiontitle[150];
char choiceA[50];
char choiceB[50];
char choiceC[50];
char choiceD[50];
char correctanswer;
};
void reward(int money)
{
gotoxy(0, 50);
printf("\t\t\t\t\tReward:$%d\n", money);
}
void lifelinemessage(int number50,int numberfriend,int numberauidence)
{
gotoxy(1, 50);
printf("\t\t\t\t\t**************************\t\t");
gotoxy(2, 50);
printf("\t\t\t\t\t[A]ChoiceA");
gotoxy(3, 50);
printf("\t\t\t\t\t[B]ChoiceB");
gotoxy(4, 50);
printf("\t\t\t\t\t[C]ChoiceC");
gotoxy(5, 50);
printf("\t\t\t\t\t[D]ChoiceD");
gotoxy(6, 50);
printf("\t\t\t\t\t[1]50/50 lifeline: %d",number50);
gotoxy(7, 50);
printf("\t\t\t\t\t[2]Call a Friend lifeline: %d",numberfriend);
gotoxy(8, 50);
printf("\t\t\t\t\t[3]Ask the Audience: %d",numberauidence);
gotoxy(9, 50);
printf("\t\t\t\t\t[4]Go home");
gotoxy(10, 50);
printf("\t\t\t\t\t**************************\t\t");
}
char letter(char word)
{
if (word >= 97 && word <= 122)
{
return word - 32;
}
else
{
return word;
}
}
char wronganswer(char input)
{
if (input != '1'&& input != '2'&& input != '3'&& input != '4')
{
printf("Wrong Input!\n");
printf("Enter the lifeline you want to choose: ");
scanf_s(" %c", &input);
input = letter(input);
return wronganswer(input);
}
else
{
return input;
}
}
char wronganswer2(char input)
{
if (input < 65 || input>68)
{
printf("Wrong Input!\n");
printf("Enter your answer: ");
scanf_s(" %c", &input);
input = letter(input);
return wronganswer2(input);
}
else
{
return input;
}
}
bool wronganswer3(char input)
{
if (input != 89 && input != 78)
{
printf("Wrong Input!\n");
printf("Are you ready for the game?(y/n) ");
scanf_s(" %c", &input);
input = letter(input);
return wronganswer3(input);
}
else if(input=='N')
{
return false;
}
}
char wronganswer4(char input)
{
if (input != 89 && input != 78)
{
printf("Wrong Input!\n");
printf("Do you want to use lifeline?(y/n) ");
scanf_s(" %c", &input);
input = letter(input);
return wronganswer4(input);
}
else if (input == 'N')
{
return false;
}
}
void lifeline50(char correct)
{
char respond[4] = {
'A','B','C','D' };
char wronganswer1, wronganswer2;
int n = 0;
int x, y = 0;
int length = strlen(respond);
for (int i = 0; i < 4; i++)
{
if (respond[i] == correct)
{
n = i;
}
}
for (int j = n; j < 4; j++)
{
respond[j] = respond[j + 1];
}
x = rand() % 2;
wronganswer1 = respond[x];
wronganswer2 = respond[x+1];
if (wronganswer1 != wronganswer2)
{
wronganswer2= wronganswer2;
}
else
{
wronganswer2= respond[rand() % 3];
}
//color(4);
printf("The two wrong choices are %c and %c\n", wronganswer1, wronganswer2);
}//50/50
void callfriend()
{
char respond[4] = {
'A','B','C','D' };
printf("The correct answer the friend gives is %c\n", respond[rand() % 4]);
}//Call a friend
void askaudience()
{
float a, b, c, d = 0;
float summary = 0;
a = rand() % 100;
b = rand() % 100;
c = rand() % 100;
d = rand() % 100;
summary = a + b + c + d;
printf("The percentage of choice A is %.2f %%\n", 100 * a / summary);
printf("The percentage of choice B is %.2f %%\n", 100*b / summary );
printf("The percentage of choice C is %.2f %%\n", 100*c / summary );
printf("The percentage of choice D is %.2f %%\n", 100*d / summary);
}
int main()
{
char input = 'a';
char answer;
int money = 0;
bool answer1 = true;
printf("\t\t\tWho Wants to Be a Millionaire\t\t\t\n");
printf("\t\t********************************************\t\t\t\n");
printf("Are you ready for the game?(y/n)");
scanf_s("%c", &input);
input=letter(input);
answer1=wronganswer3(input);
if (answer1 == false)
{
return 0;
}
system("cls");
/*char lifeline50[30] = " ";
char lifelinecallfriend[30] = " ";
char lifelineaskauidence[30] =" ";*/
srand(time(NULL));
/*
//lifeline50(correct);
//callfriend();
askaudience();
system("PAUSE");
system("cls");
//system("PAUSE");*/
//The questions and answers
game question1;
question1.questionNumber = 1;
question1.gameReward = 500;
strcpy_s(question1.questiontitle, "Which company is The Legend of Zelda: Breath of the Wild from?");
strcpy_s(question1.choiceA, "Nintendo");
strcpy_s(question1.choiceB, "Capcom");
strcpy_s(question1.choiceC, "Riot");
strcpy_s(question1.choiceD, "Valve");
question1.correctanswer='A';
game question2;
question2.questionNumber = 2;
question2.gameReward = 1000;
strcpy_s(question2.questiontitle, "What kind of game is DOTA2?");
strcpy_s(question2.choiceA, "MMORPG");
strcpy_s(question2.choiceB, "MOBA");
strcpy_s(question2.choiceC, "ARPG");
strcpy_s(question2.choiceD, "JRPG");
question2.correctanswer='B';
game question3;
question3.questionNumber = 3;
question3.gameReward = 2000;
strcpy_s(question3.questiontitle, "How many roles does League of Legends have?");
strcpy_s(question3.choiceA, "144");
strcpy_s(question3.choiceB, "142");
strcpy_s(question3.choiceC, "140");
strcpy_s(question3.choiceD, "143");
question3.correctanswer='A';
game question4;
question4.questionNumber = 4;
question4.gameReward = 3000;
strcpy_s(question4.questiontitle, "How many years has World of Warcraft been running?");
strcpy_s(question4.choiceA, "13");
strcpy_s(question4.choiceB, "18");
strcpy_s(question4.choiceC, "15");
strcpy_s(question4.choiceD, "14");
question4.correctanswer='C';
game question5;
question5.questionNumber = 5;
question5.gameReward = 5000;
strcpy_s(question5.questiontitle, "Which game has the first prize in the world?");
strcpy_s(question5.choiceA, "DOTA2");
strcpy_s(question5.choiceB, "LEAGUE OF LEGENDS");
strcpy_s(question5.choiceC, "CS.GO");
strcpy_s(question5.choiceD, "PUBG");
question5.correctanswer='A';
game question6;
question6.questionNumber = 6;
question6.gameReward = 7500;
strcpy_s(question6.questiontitle, "What kind of game is final Fantasy 14?");
strcpy_s(question6.choiceA, "MOBA");
strcpy_s(question6.choiceB, "MMORPG");
strcpy_s(question6.choiceC, "JRPG");
strcpy_s(question6.choiceD, "RTS");
question6.correctanswer='B';
game question7;
question7.questionNumber = 7;
question7.gameReward = 10000;
strcpy_s(question7.questiontitle, "When did the PORTAL come out of the game?");
strcpy_s(question7.choiceA, "2005");
strcpy_s(question7.choiceB, "2077");
strcpy_s(question7.choiceC, "2007");
strcpy_s(question7.choiceD, "2009");
question7.correctanswer='C';
game question8;
question8.questionNumber = 8;
question8.gameReward = 15000;
strcpy_s(question8.questiontitle, "Which game is the first to have an official e-sports competition?");
strcpy_s(question8.choiceA, "STARCRAFT");
strcpy_s(question8.choiceB, "LEAGUE OF LEGENDS");
strcpy_s(question8.choiceC, "DOTA2");
strcpy_s(question8.choiceD, "CS 1.6");
question8.correctanswer='A';
game question9;
question9.questionNumber = 9;
question9.gameReward = 25000;
strcpy_s(question9.questiontitle<