Hi again. i'm back with some questions that have to do with a project im working on for the college.
This is gonna be a bit big and if there is any variable that u dont understand its use then ask me please.
So this time we have to do the following :
First i have to insert into a struct the details of every flight for 10 flights.Those are :
The "flights code" ( example : Flight OA123)
The "from" ( wich city the airplane takes off)
The "to"(wich city the airplane lands)
The "date" (date of take off)
The "time" ( time of take off)
The "price" ( the price of the ticket for each one)
The " sits" ( that each plane has for passengers)
and then
the programm should perform 2 operations.
1)Find flights.
This means that the user inputs a a departure city, a land city, and a date and searches for a flight that meets theese criteria.
If there is no flight matching the criteria it will not terminate but instead it will give the user the opportunity to search again or exit.ofcourse the results will be displayed on screen!
2)It will be able for the user to get sits.
By this i mean that the user can get a ticket for a specific flight like this:
The user inputs a flight code. If there is a flight with that code the user can buy a ticket.So if a flight has 150 sits, only 150 tickets can be bought/sold.If a flight has 120 sits then only 120 tickets can be bought/sold.If the amount that the user is trying to "buy" exceeds the amount of available sits left on the specific then the user cannot buy those sits and will get a message for the amount of sits left.If he wants 3 but there are only to then smthing like " There are only 2 more sits available" will be displayed.
the code i have so far is this :
Code:
#include <stdio.h>
#include <string>
int i,opt;
struct info
{
char from[25],to[25],code[6];
int date,time,price,sits;
};
struct info flight[10];
void insert(),find(),sits();
void insert() //inserts values
{
flight[0].code="AO000";
flight[1].code="AO001";
flight[2].code="AO002";
flight[3].code="AO003";
flight[4].code="AO004";
flight[5].code="AO005";
flight[6].code="AO006";
flight[7].code="AO007";
flight[8].code="AO008";
flight[9].code="AO009";
flight[0].from="Athens";
flight[1].from="Thessaloniki";
flight[2].from="Larisa";
flight[3].from="Patra";
flight[4].from="Trikala";
flight[5].from="Xania";
flight[6].from="Agio Or;os";
flight[7].from="Lamia";
flight[8].from="Larnaka";
flight[9].from="Aidonia";
flight[0].to="Patra";
flight[1].to="Trikala";
flight[2].to="Xania";
flight[3].to="Agio Oros";
flight[4].to="Aidonia";
flight[5].to="Lamia";
flight[6].to="Athens";
flight[7].to="Larnaka";
flight[8].to="Patra";
flight[9].to="Thessaloniki";
flight[0].date=0801;
flight[1].date=0301;
flight[2].date=0403;
flight[3].date=1205;
flight[4].date=1611;
flight[5].date=2109;
flight[6].date=0709;
flight[7].date=1104;
flight[8].date=2708;
flight[9].date=2202;
flight[0].time=1249;
flight[1].time=2210;
flight[2].time=2015;
flight[3].time=1620;
flight[4].time=0930;
flight[5].time=0730;
flight[6].time=2400;
flight[7].time=1145;
flight[8].time=1425;
flight[9].time=1945;
flight[0].price=50;
flight[1].price=39;
flight[2].price=42;
flight[3].price=49;
flight[4].price=60;
flight[5].price=80;
flight[6].price=30;
flight[7].price=20;
flight[8].price=66;
flight[9].price=45;
flight[0].sits=150;
flight[1].sits=100;
flight[2].sits=130;
flight[3].sits=170;
flight[4].sits=158;
flight[5].sits=134;
flight[6].sits=160;
flight[7].sits=120;
flight[8].sits=140;
flight[9].sits=150;
}
void find()/* searches for a specific flight*/
{
char from[20],to[20];
int i,date;
printf("A\n Anazitisi Priseon : ");
printf("\n Parakalo eisagete poli anaxorisis : ");
scanf("%s",from);
printf("\n Parakalo eisagete poli afiksis");
scanf("%s",to);
printf("\n Parakalo eisagete imerominia");
scanf("%d",date);
printf("\n Oi akolouthes ptiseis brethikan : ");
for (i=0;i<10;i++)
{
if ((!strcmp(flight[i].from,from))&&(!strcmp(flight[i].to,to))&&(flight[i].date==date))
{
printf("\n Ptisis: %s ,Wra: %d , Timi: %d , Thesis : %d",flight[i].code,flight[i].time,flight[i].price,flight[i].sits);
}
}
}
void sits() /* user gets tickets*/
{
char kod[6]; //kod = code of a flight
int thesis,date; //thesis = sits a user trys to buy
printf("\n Kratisi theseon : ");
printf("\n Parakalo epilexte ptisi : "); // user inputs a flight code
scanf("%s",kod);
printf("\n Thesis pou thelete na kratisete : "); /*user inputs amount of sits to buy*/
scanf("%d",&thesis);
for (i=0;i<10;i++)
{
if (strcmp(flight[i].code,kod)==0)
{
if((flight[i].sits-thesis)>=0)
{
flight[i].sits=flight[i].sits-thesis;
printf("\n Oi thesis kratithikan. Kostos : %d",flight[i].price*thesis);
}
}
}
}
int main()
{
printf("\n 1. Anazitisi Ptisis :");
printf("\n 2. Kratisi theseon :");
printf("\n 3. Eksodos :");
printf("\n Parakalo doste tin epilogi sas : ");
scanf("%d",&opt);
insert();
if ( opt==1)
{
find();
}
if (opt==2)
{
sits();
}
if (opt==3) //opt 3 exits the programm
{
printf("Eksodos programmatos");
}
}
i cant compile it because i get an error with the insert of values into the struct, but i cant understand why :S
From line 16-25 i get " ISO c++ forbid the ssigment of arrays"
From 26-45 i get" incompatible types of assigment of 'const char [number]' to 'char[25]'
if you can help me plz dont be late because i have to deliver this one 18/12 until midnight at least and i got like less than 20 hours. plus i need to sleep cause its almost 5 in the morning here :S
Thanks in advance
~ Cursy