gpt4 book ai didi

c - 具有多个输入的 scanf 和循环 - c

转载 作者:太空宇宙 更新时间:2023-11-04 04:27:52 27 4
gpt4 key购买 nike

如何让我的程序接受多个输入(使用 scanf 和循环)并在计算后分别打印结果?

我的程序接受六个输入但只显示一个输出。我想获得以下输出:sample output I want .

    #include <stdio.h>
#include <string.h>

main() {
// Declaring variables
char name[25];
int hours, rate, gross, bonus, counter;

printf(" A program to determine the gross pay for six Employees\n Please Enter the Name, No. of hours worked and hourly rate respectively\n");

for (counter = 1; counter <= 6; counter++) {
scanf("%s %d %d", &name, &hours, &rate);
gross = hours * rate; // determining the gross pay
printf("%s %d %d %d\n", name, hours, rate, gross);
}
}

最佳答案

正如@LPs 在评论中提到的那样。更改以下行
scanf("%s %d %d",&name,&hours,&rate);
到这个
scanf("%s %d %d",name ,&hours,&rate);

scanf("%s %d %d",&name[0],&hours,&rate);

关于c - 具有多个输入的 scanf 和循环 - c,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39744031/

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