gpt4 book ai didi

c - 如何同时打印两个输入的输出?

转载 作者:行者123 更新时间:2023-11-30 21:02:19 25 4
gpt4 key购买 nike

代码:

#include <stdio.h>

int main()
{
int w,x,y,z;
float v;
printf("Enter the driver salary\n");
scanf("%d",&x);
printf("Enter the car mileage in km per litre\n");
scanf("%d",&y);
printf("Enter the cost of petrol per litre\n");
scanf("%d",&z);
printf("Enter the taxi fare for a km\n");
scanf("%d",&w);
printf("Enter the distance of travel\n");
scanf("%f",&v);
if(w==200 && y==10 && z==60 && x== 20 && v==10.5)
printf("Minimal cost travel is by taxi\n");
else
printf("Minimal cost travel is by audi\n");
return 0;
}

对于 w 的两组不同的输入值, y , z , x , v ,我需要同时打印两个输出语句。我正在获得第一个输出,但如何同时获得两个输出?

最佳答案

如果你想同时输出有一个标志数组来存储结果。另外你可能想将 10.5 的值存储在 float 中。 Read more 。我在您的代码中添加了几行,检查它是否有效:

#include<stdio.h>
int main()
{
float l=10.5; //to be safe about float rounding up
int i,fl[2]; //stores results for output

for(i=0;i<2;i++) //add this
{
int w,x,y,z;
float v;
printf("Enter the driver salary\n");
scanf("%d",&x);
printf("Enter the car mileage in km per litre\n");
scanf("%d",&y);
printf("Enter the cost of petrol per litre\n");
scanf("%d",&z);
printf("Enter the taxi fare for a km\n");
scanf("%d",&w);
printf("Enter the distance of travel\n");
scanf("%f",&v);

if(w==200 && y==10 && z==60 && x== 20 && v==l)
fl[i]=1;
else
fl[i]=0;
}
for(i=0;i<2;i++)
{
if(fl[i]==1)
printf("Case %d : Minimal cost travel is by taxi\n",i+1);
if(fl[i]==0)
printf("Case %d : Minimal cost travel is by audi\n",i+1);
} //close braces

return 0;
}

关于c - 如何同时打印两个输入的输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30994495/

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