C中的程序有什么问题? [英] What is wrong with the program in C?
本文介绍了C中的程序有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include<stdio.h>
#include<conio.h>
struct boat
{ int age;
char name[30];
}passengerinfo[2];
void main()
{ clrscr();
int a;
printf("\nEnter the number of tickets:");
scanf("%d",&a);
for(int i=0;i<a;i++)>
{ printf("\nEnter name[%d]:",i+1);
scanf("%s",&passengerinfo[i].name);
printf("\nEnter age[%d]:",i+1);
scanf("%d",&passengerinfo[i].age);
}
printf("\nThe boarders of the boats:");
for(i=0;i<a;i++)>
{ printf("\nName:%s",passengerinfo[i].name);
printf("\tAge:%d",passengerinfo[i].age);
}
for(i=0;i<a;i++)>
{
if(passengerinfo[i].age>0&&passengerinfo[i].age<18)
printf("\nFare=:100");
else if(passengerinfo[i].age>=18&&passengerinfo[i].age<60)
printf("\nFare:=200");
else if(passengerinfo[i].age==0||passengerinfo[i].age>=60)
printf("\nFare=:300");
else
printf("\nIncorrect age");
}
getch();
}
我可以输入4人的姓名和年龄。对于大于4的数字(例如:5张票,6张票等)我没有得到任何显示,但我可以输入。请帮我纠正显示。谢谢。
I am able to type the name and age for 4 people. For numbers greater than 4(for ex: for 5 tickets, 6tickets,etc.) I do not get any displays but I can type. Please help me to rectify the display. Thanks.
推荐答案
你只创建了一个包含2个成员的数组
You only created an array of 2 members
passengerinfo[2]
尝试
Try
passengerinfo[10]
AND也限制输入值的数量到10对。
AND also limit the number of values input to 10 pairs.
这篇关于C中的程序有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文