Before I had problems passing an int array, now it is returning it...
Areas of importance is the last function "int* ReadPrices(void)" and lien 25.
Thanks!
data.dat is:
Code:
5 10 15 20 25 30 35 40 45 50 55 60 65 70 75
My code is:
Code:
#include <stdio.h>
#include <stdlib.h>
void seatChart (int AvailableSeats[15][20]);
int* ReadPrices(void);
int main()
{
int choice;
int row;
int seat;
int i;
int AvailableSeats[15][20] = {0}; //seats[row][seat]
int ticketsSold = 0;
int sale;
int PriceList[16];
PriceList = ReadPrices();
for(;;)
{
seatChart(AvailableSeats);
printf("\n\nMenu:");
printf("\n1) Buy ticket");
printf("\n2) Total sell and exit");
printf("\n\nEnter your choice : ");
scanf("%d", &choice);
if (choice == 1)
{
printf("\n\nEnter row: ");
scanf("%d", &row);
printf("\nEnter seat: ");
scanf("%d", &seat);
if (row<0 || row >14 || seat<0 || seat>19)
{
printf("Invalid seat choice");
}
else if(AvailableSeats[row][seat] == 0)
{
AvailableSeats[row][seat] = 1;
ticketsSold++;
sale = sale + PriceList[row];
}
else
{
printf("\nSeat is already taken");
}
continue;
}
if(choice == 2)
{
printf("\n\nTOTAL TICKETS SOLD: %d", ticketsSold);
printf("\nTOTAL REVENUE: Y");
break;
}
printf("Invalid choice");
ticketsSold--;
}
return 0;
}
void seatChart (int AvailableSeats[15][20])
{
int i;
int o;
printf("\n* Seats available");
printf("\n# Reserved Seats");
printf("\nSeats: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19");
for(o = 0; o<=14; o++)
{
printf("\nRow %2d", o);
for(i = 0; i<=19; i++)
{
if(AvailableSeats[o][i] == 1)
{
printf(" #");
}
else
{
printf(" *");
}
}
}
}
int* ReadPrices(void)
{
int i;
int tempPriceList[16];
FILE* fts;
fts = fopen("data.dat", "r");
for(i = 0;i<=14;i++)
{
fscanf(fts, "%d ", &tempPriceList[i]);
}
for(i=0;i<=14;i++)
printf("%d ", tempPriceList[i]);
return tempPriceList;
}