#include<iostream>
using namespace std;
int main(void)
{
int select,select1;
int price,totalprice;
int i,j;
int city_array[5]={40,60,65,100,110};
cout<<" do you want to start the program <0 > to exit any other key to start \n";
cin>>select;
if(select==0)
{
exit(0);
else
system("cls");
cout<<"- welcome to airplane program -\n";
cout<<" these are the cities and prices<tickets are around trip>\n\n";
cout<<" 1-> antalya <40$>\n";
cout<<" 2-> ankara <60$>\n";
cout<<" 3-> istanbul <100$>\n";
cout<<" 4-> izmir <65$>\n";
cout<<" 5-> trabzon <110$>\n\n";
cout<<" which city do you want to go?<1-5>:";
cin>>select1;
cout<<"\n\n\n\n\n\n\n";
switch(select1)
{
case 1:
cout<<"how many tickets do you want to buy to this city:";
cin>>i;
price=city_array[0]*i;
cout<<"Price"<<city_array[0];
cout<<"total price"<<price;
break;
case 2:
cout<<"how many tickets do you want to buy to this city";
cin>>i;
price=city_array[1]*i;
cout<<"Price"<<city_array[1];
cout<<"total price"<<price;
break;
case 3:
cout<<"how many tickets do you want to buy to this city";
cin>>i;
price=city_array[2]*i;
cout<<"Price"<<city_array[2];
cout<<"total price"<<price;
break;
case 4:
cout<<"how many tickets do you want to buy to this city";
cin>>i;
price=city_array[3]*i;
cout<<"Price"<<city_array[3];
cout<<"total price"<<price;
break;
case 5:
cout<<"how many tickets do you want to buy to this city";
cin>>i;
price=city_array[4]*i;
cout<<"Price"<<city_array[4];
cout<<"total price"<<price;
break;
default:
cout<<"invalid choose please try again ";
break;
tags.
[code]if(select==0)
{//this parenthesis is not matched
exit(0);
else ...
1 2 3 4 5 6 7 8 9 10 11
switch(select1)
{
case 1:
cout<<"how many tickets do you want to buy to this city:";
cin>>i;
price=city_array[0]*i;
cout<<"Price"<<city_array[0];
cout<<"total price"<<price;
break;
//etc...
}//switch (select 1)
This code is bad. You put things in array to avoid it. It could be
yes until user press 0 to exit program will ask again again
and every return back program will clean everything and start again
how do you think i can do it ?
Well, this isn't really the task for a for loop, but whatever.
Just wrap the code you want to repeat in for(;;){ and }. Note for(;;) is an infinite loop (this is not a problem, since you'll exit it with exit(0);). You could use while(true) as well.