我想编写一个C程序,可以要求用户输入yes或no来继续后续功能。 如果是,它应该调用一个函数,如果不是,它应该返回0。
到目前为止我已经完成了
#include <stdio.h>
#include <stdlib.h>
int main()
{
char y, n, Y, N, ans;
printf("Would you like to continue ?:\t");
scanf("%c",&ans);
switch (ans)
{
case 'y':
{
void convert();
return ;
}
break;
default:
{
return (0);
}
break;
return 0;
}
}
void convert (){
printf("hello");
}
如何调用名为convert的函数?
答案 0 :(得分:0)
感谢您的反馈意见。 在这里,我得到了你的帮助。
#include <stdio.h>
#include <stdlib.h>
int main()
{
char y, n, Y, N, ans;
printf("Would you like to continue ?:\t");
scanf("%c",&ans);
switch (ans)
{
case 'y':
case 'Y':
convert();
break;
case 'N':
case 'n':
return(0);
break;
default:
{
return (0);
}
break;
return 0;
}}
void convert (){
printf("Hello");
}
答案 1 :(得分:0)
大家好,我已经完成了将马来西亚林吉特的金额转换为等值美元的任务。
我想编写一个C程序,可以要求用户输入yes或no来继续后续功能。
如下图所示,我完成了编码
#include <stdio.h>
#include <stdlib.h>
int main()
{
char y, n, Y, N, ans;
printf("\nWould you like to continue ?:\t");
scanf("%c",&ans);
switch (ans)
{
case 'y':
case 'Y':
convert();
break;
case 'N':
case 'n':
return(0);
break;
default:
{
return (0);
}
break;
return 0;
}
while (ans==y || ans==Y);
return main();
}
int convert (){
float ia,ca;
printf("\nEnter amount in Ringgit Malaysia : RM ");
scanf("%f",&ia);
ca=ia/3.30;
printf("\nRM %.2f is equals to USD %.2f\n\n\n",ia,ca);
return main();
}
但我的输出显示如下
Would you like to continue ? : y
Enter amount in Ringgit Malaysia : RM 100
RM 100.00 is equals to USD 30.30
Would you like to continue ? :
Would you like to continue ? : y
Enter amount in Ringgit Malaysia : RM 100
RM 100.00 is equals to USD 30.30
Would you like to continue ? :
Would you like to continue ? : n
我的问题是为什么问题会重复两次?
顺便说一下输出应该是这样的
Would you like to continue ? : y
Enter amount in Ringgit Malaysia : RM 100
RM 100.00 is equals to USD 30.30
Would you like to continue ? : y
Enter amount in Ringgit Malaysia : RM 100
RM 100.00 is equals to USD 30.30
Would you like to continue ? : n