C 语言 用while loop 停不下来了

问题描述:

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):
1个回答 分类:综合 2014-10-17

问题解答:

我来补答
/*Do you like The Big Bang Theory (1-yes, 2- no):1Do you like The Big Bang Theory (1-yes, 2- no):1Do you like The Big Bang Theory (1-yes, 2- no):1Do you like The Big Bang Theory (1-yes, 2- no):2Do you like The Big Bang Theory (1-yes, 2- no):3INVALID selection.Do you like The Big Bang Theory (1-yes, 2- no):qscore = 135Press 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;
}
 
 
展开全文阅读
剩余:2000