C 语言 用while loop 停不下来了Part 1:Reading user input,keeping track of scores.Write a program that asks one question,records the response,keeps track of a "score," and prints out the score after a response.This question needs to have a scor

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/03 22:38:08
C 语言 用while loop 停不下来了Part 1:Reading user input,keeping track of scores.Write a program that asks one question,records the response,keeps track of a

C 语言 用while loop 停不下来了Part 1:Reading user input,keeping track of scores.Write a program that asks one question,records the response,keeps track of a "score," and prints out the score after a response.This question needs to have a scor
C 语言 用while loop 停不下来了
Part 1:Reading user input,keeping track of scores.
Write a program that asks one question,records the response,keeps track of a "score," and
prints out the score after a response.This question needs to have a score associated with the
answer chosen.For example,if the answer to the question is one that you like,the score should
reflect that answer.In the example below,if the user enters a 1,the program will add 60 to
their score,if the user enters a 2,then 45 is subtracted from their score.It is up to you to
determine your scoring system.Your program should continue to ask for the answer until the
user enters a valid response.
Here is an example of a question:
Do you like The Big Bang Theory (1-yes,2- no):1
score = 60
Here is an alternate run:
Do you like The Big Bang Theory (1-yes,2- no):2
score = -45
Here is an alternate run:
Do you like The Big Bang Theory (1-yes,2- no):3
INVALID selection.
Do you like The Big Bang Theory (1-yes,2- no):

C 语言 用while loop 停不下来了Part 1:Reading user input,keeping track of scores.Write a program that asks one question,records the response,keeps track of a "score," and prints out the score after a response.This question needs to have a scor

/*

Do you like The Big Bang Theory (1-yes, 2- no):1

Do you like The Big Bang Theory (1-yes, 2- no):1

Do you like The Big Bang Theory (1-yes, 2- no):1

Do you like The Big Bang Theory (1-yes, 2- no):2

Do you like The Big Bang Theory (1-yes, 2- no):3

INVALID selection.

Do you like The Big Bang Theory (1-yes, 2- no):q

score = 135

Press any key to continue

*/

#include <stdio.h>

int main() {
int an,score = 0;
while(printf("Do you like The Big Bang Theory (1-yes, 2- no):"),
scanf("%d",&an) == 1) {
if(an == 1) score += 60;
else if(an == 2) score -= 45;
else printf("INVALID selection.\n");
}
printf("score = %d\n",score);
return 0;
}