gpt4 book ai didi

当用户输入数字时,计数值并再次返回到代码的开头

转载 作者:行者123 更新时间:2023-11-30 14:43:41 25 4
gpt4 key购买 nike

程序计算出输入的内容后,会打印出该值,然后程序会询问是否继续,如果我按“Y”,程序将从用户输入数字时的开头开始。问题是如果用户按“Y”如何使程序回到开头?

#include <stdio.h>
#include <stdlib.h>
void VOne();
int main(void) {
VOne();
return 0;
}

void VOne() {
int i,quiz,exer,test,Final,FV,back;
char again;
while (1) {

printf("Input Value : ");
scanf("%d %d %d %d",&quiz,&exer,&test,&Final );
FV = 0.10+(0.10*quiz)+(0.15*exer)+(0.30*test)+(0.35*Final);
printf("%d\n",FV );
if (FV >= 75) {
printf("You pass the this class\n" );
}
else {
printf("You've to take this class again in the next term\n");
}
printf("You want to input again?\n'Y'or'N\n");
scanf("%c ",&again );
if (again == 'y') {
continue;
}
}
return;
}

最佳答案

这应该有效。

#include <stdio.h>
#include <stdlib.h>
void VOne();
int main(void) {
VOne();
return 0;
}

void VOne() {
int i,quiz,exer,test,Final,FV,back;
char again;
while (1) {

printf("Input Value : ");
scanf("%d %d %d %d",&quiz,&exer,&test,&Final );
FV = 0.10+(0.10*quiz)+(0.15*exer)+(0.30*test)+(0.35*Final);
printf("%d\n",FV );
if (FV >= 75) {
printf("You pass the this class\n" );
}
else {
printf("You've to take this class again in the next term\n");
}
printf("You want to input again?\n'Y'or'N\n");
scanf(" %c ",&again );
if (again == 'y' || again == 'Y') {
continue;
}
else break;
}
return;
}

关于当用户输入数字时,计数值并再次返回到代码的开头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53794524/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com