Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
#include <stdio.h>

int main()
{
	char name[20];
	int pass, qticket;
	float A=185.50, B=190.50, C=210.00, D= 185.50, E=190.50, F=210.00,i,n;
	char code, YN;
	float sum;
	
	printf("\t\t\t-S E L A N G O R  A I R W A Y S- \n");
	printf("\n");
	printf("_______________________________________________________________________________________\n");
	printf("|  DESTINATION CODE  |  DESTINATION     | DEPARTURE TIME | ARRIVAL TIME | TICKET PRICE |\n");
	printf("|____________________|__________________|________________|______________|______________|\n");
	printf("|         A          | KUANTAN          | 9:30 am        | 10:40 pm     | RM 185.50    |\n");
	printf("|--------------------|------------------|----------------|--------------|--------------|\n");
	printf("|         B          | KUALA TERENGGANU | 10:30 am       | 12:00 pm     | RM 190.50    |\n");
	printf("|--------------------|------------------|----------------|--------------|--------------|\n");
	printf("|         C          | KOTA BHARU       | 11:30 am       | 1:30 pm      | RM 210.00    |\n");
	printf("|--------------------|------------------|----------------|--------------|--------------|\n");
	printf("|         D          | JOHOR BHARU      | 10:00 am       | 11:15 pm     | RM 185.50    |\n");
	printf("|--------------------|------------------|----------------|--------------|--------------|\n");
	printf("|         E          | PENANG           | 11:00 am       | 12:30 pm     | RM 190.50    |\n");
	printf("|--------------------|------------------|----------------|--------------|--------------|\n");
	printf("|         F          | ALOR SETAR       | 12:00 am       | 2:00 pm      | RM 210.00    |\n");
	printf("|____________________|__________________|________________|______________|______________|\n");
	
	do
	{
	printf(" \n\t\t\t-PASSENGER INFORMATION-\n");
	printf("\n");
	printf(" NAME              :", name);
	scanf("%s", &name);
	printf(" PASSPORT NUMBER   :", pass);
	scanf("%d", &pass);	
	printf(" DESTINATION CODE  :", code);
	scanf("%s", &code);
	printf(" QUANTITY OF TICKET:", qticket);
	scanf("%d",&qticket);
		
	if (code=='A' && 'a')
	{
	printf("_______________________________________________________________________________________\n");	
	printf("|  DESTINATION CODE  |  DESTINATION     | DEPARTURE TIME | ARRIVAL TIME | TICKET PRICE |\n");
	printf("|____________________|__________________|________________|______________|______________|\n");
	printf("|         A          | KUANTAN          | 9:30 am        | 10:40 pm     | RM %.2lf    |\n", qticket*A);
	printf("|____________________|__________________|________________|______________|______________|\n");
	}
	else if (code=='B' && 'b')
	{
	printf("_______________________________________________________________________________________\n");
	printf("|  DESTINATION CODE  |  DESTINATION     | DEPARTURE TIME | ARRIVAL TIME | TICKET PRICE |\n");
	printf("|____________________|__________________|________________|______________|______________|\n");
	printf("|         B          | KUALA TERENGGANU | 10:30 am       | 12:00 pm     | RM %.2lf    |\n",qticket*B);
	printf("|____________________|__________________|________________|______________|______________|\n");
	}
	else if (code=='C' && 'c')
	{
	printf("_______________________________________________________________________________________\n");
	printf("|  DESTINATION CODE  |  DESTINATION     | DEPARTURE TIME | ARRIVAL TIME | TICKET PRICE |\n");
	printf("|____________________|__________________|________________|______________|______________|\n");
	printf("|         C          | KOTA BHARU       | 11:30 am       | 1:30 pm      | RM %.2lf    |\n",qticket*C);
	printf("|____________________|__________________|________________|______________|______________|\n");
	}
	else if (code='D' && 'd')
	{
	printf("_______________________________________________________________________________________\n");
	printf("|  DESTINATION CODE  |  DESTINATION     | DEPARTURE TIME | ARRIVAL TIME | TICKET PRICE |\n");
	printf("|____________________|__________________|________________|______________|______________|\n");
	printf("|         D          | JOHOR BHARU      | 10:00 am       | 11:15 pm     | RM %.2lf    |\n",qticket*D);
	printf("|____________________|__________________|________________|______________|______________|\n");
	}
	else if (code=='E' && 'e')
	{
	printf("_______________________________________________________________________________________\n");
	printf("|  DESTINATION CODE  |  DESTINATION     | DEPARTURE TIME | ARRIVAL TIME | TICKET PRICE |\n");
	printf("|____________________|__________________|________________|______________|______________|\n");
	printf("|         E          | PENANG           | 11:00 am       | 12:30 pm     | RM %.2lf    |\n",qticket*E);
	printf("|____________________|__________________|________________|______________|______________|\n");
	}
	else if (code=='F' && 'f')
	{
	printf("_______________________________________________________________________________________\n");
	printf("|  DESTINATION CODE  |  DESTINATION     | DEPARTURE TIME | ARRIVAL TIME | TICKET PRICE |\n");
	printf("|____________________|__________________|________________|______________|______________|\n");
	printf("|         F          | ALOR SETAR       | 12:00 am       | 2:00 pm      | RM %.2lf    |\n",qticket*F);
	printf("|____________________|__________________|________________|______________|______________|\n");
	}
	printf("CONTINUE? (Y/N) :");
	scanf(" %c", &YN);
	printf("\n");	
	}while(YN=='Y' && 'y');
	 for(i=0;i<n;i++)
	 {
	 	sum=sum+(qticket[i]*i);
	 }
	
	printf("TOTAL AMOUNT:%.2lf\n",sum);
	printf("\t\t-THANK YOU AND HAVE A NICE JOURNEY WITH SELANGOR AIRWAYS-");
	
	
	
	return 0;
}


What I have tried:

[Error] subscripted value is neither array nor pointer nor vector
Posted
Updated 11-Apr-21 3:51am
Comments
Patrice T 11-Apr-21 9:38am    
The error message also tells you the position of error.
Rick York 11-Apr-21 12:02pm    
Have a look at the toupper function also.

C++
if (code=='A' && 'a')

These are not valid statements. You must tell the compiler what the small a is being compared against:
C++
if (code=='A' || code=='a') // using OR operator

You also cannot use the AND operator there. A variable cannot be equal to 'A' and also equal to 'a'.
 
Share this answer
 
Apart from what Richard has mentioned you need to change the sum in the lass loop to resolve your error.

for (i = 0; i < n; i++)
{
    // sum = sum + (qticket[i] * i);
    sum = sum + (qticket * i);
}

printf("TOTAL AMOUNT:%.2lf\n", sum);
printf("\t\t-THANK YOU AND HAVE A NICE JOURNEY WITH SELANGOR AIRWAYS-");
 
Share this answer
 

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