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/06/27 18:22:43
![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](/uploads/image/z/5578384-40-4.jpg?t=C+%E8%AF%AD%E8%A8%80+%E7%94%A8while+loop+%E5%81%9C%E4%B8%8D%E4%B8%8B%E6%9D%A5%E4%BA%86Part+1%3AReading+user+input%2Ckeeping+track+of+scores.Write+a+program+that+asks+one+question%2Crecords+the+response%2Ckeeps+track+of+a+%22score%2C%22+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 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;
}