Click here to Skip to main content
15,885,537 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
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();
}



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.
Posted
Updated 10-Jun-15 6:14am
v3
Comments
Mohibur Rashid 11-Jun-15 2:41am    
What is your compiler version?

1 solution

You only created an array of 2 members

C++
passengerinfo[2]

Try

C++
passengerinfo[10]

AND also limit the number of values input to 10 pairs.
 
Share this answer
 
Comments
CPallini 10-Jun-15 16:27pm    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900