else without previous if

hi,i am new to c programming.after i compile my coding,get error else without previous if.so many times i try to solve this problem already..but this error
still continue...please help me...thanks...

This is my coding.

#include<stdio.h>
#include<conio.h>
main()
{

int languages,position,position2;

do
{
printf("\n>Choose Languages/Pilih Bahasa<\n");

printf("\n1.Malay languages/Bahasa Melayu");
printf("\n2.English languages/Bahasa Inggeris\n");
scanf("%d",&languages);
}
while(languages==0 || languages>=3);


if (languages==1)
{
printf("\nAnda telah memilih Bahasa Melayu");
printf("\nOleh itu,Sila tekan mana-mana kekunci untuk teruskan..");
getch();
}
else
{
printf("\nYou have choosen English languages");
printf("\nSo,Press any key to continue..");
getch();
}





if (languages==1)
{



printf("\n\n>Pilih Kedudukan Tempat Duduk<\n");
printf("\n>>Perhatian<<");
printf("\n*Anda perlu memilih satu kedudukan sahaja*");
printf("\n\n1.Kiri");
printf("\n2.Tengah");
printf("\n3.Kanan\n");
scanf("%d",&position);
}
while(position==0 || position>=4){
}





else
{



printf("\n\n>Choose Position of Seats<\n");
printf("\n>>Attention<<");
printf("\n*You should choose either one position below only*");

printf("\n\n1.Right");
printf("\n2.Middle");
printf("\n3.Left\n");
scanf("%d",&position2);
}
while(position2==0 || position2>=4){
}

getch();
return 0;
}
Else should start where the } of your if ends. Every else must have and if.

while loop should be inside if or else , where ever its use is.

In your program, while loop is breaking the connection of if and else

Hope this helps

This will not give error:

#include<stdio.h>
#include<conio.h>
main()
{

int languages,position,position2;

do
{
printf("\n>Choose Languages/Pilih Bahasa<\n");

printf("\n1.Malay languages/Bahasa Melayu");
printf("\n2.English languages/Bahasa Inggeris\n");
scanf("%d",&languages);
}
while(languages==0 || languages>=3);


if (languages==1)
{
printf("\nAnda telah memilih Bahasa Melayu");
printf("\nOleh itu,Sila tekan mana-mana kekunci untuk teruskan..");
getch();
}
else
{
printf("\nYou have choosen English languages");
printf("\nSo,Press any key to continue..");
getch();
}





if (languages==1)
{



printf("\n\n>Pilih Kedudukan Tempat Duduk<\n");
printf("\n>>Perhatian<<");
printf("\n*Anda perlu memilih satu kedudukan sahaja*");
printf("\n\n1.Kiri");
printf("\n2.Tengah");
printf("\n3.Kanan\n");
scanf("%d",&position);



//while loop is inside if {}
while(position==0 || position>=4)
{
//dothis

}




}//if is ending here ************

else
{



printf("\n\n>Choose Position of Seats<\n");
printf("\n>>Attention<<");
printf("\n*You should choose either one position below only*");

printf("\n\n1.Right");
printf("\n2.Middle");
printf("\n3.Left\n");
scanf("%d",&position2);
}
while(position2==0 || position2>=4){
}

getch();
return 0;
}
Please use code tags and sane indentation when posting code.
http://www.cplusplus.com/articles/jEywvCM9/
thanks a lot Mr sherkhan11......
Hi,i am new to c programming.. below show that my final project of my coding..coding is fine,but i want repeat my program from main function after first time attempt is finish without any error..i know that want to add looping to repeat program...but i don't know the concept..please help me to solve this problem..thanks..please..


/*Coding of Our Project*/
#include<stdio.h>
#include<conio.h>
main()
{

int languages,teater,movie,showtime;
int seats,seats2,jumlah,total2;
float total;



do
{
printf("\n>Choose Languages/Pilih Bahasa<\n");

printf("\n1.Malay languages/Bahasa Melayu");
printf("\n2.English languages/Bahasa Inggeris\n");
scanf("%d",&languages);
}
while(languages==0 || languages>=3);


if (languages==1)
{
printf("\nAnda telah memilih Bahasa Melayu");
printf("\nOleh itu,Sila tekan mana-mana kekunci untuk teruskan..");
getch();
}
else
{
printf("\nYou have choosen English languages");
printf("\nSo,Press any key to continue..");
getch();
}

do
{

if(languages==1)
{

printf("\n\n>Pilih Teater<\n");
}
else
{

printf("\n\n>Choose Theater<\n");
}
printf("\n1.GSC(Golden Screen Cinemas)");
printf("\n2.MBO(Malaysian Box Office)");
printf("\n3.Lotus Five Star\n");

scanf("\n%d",&teater);
}
while(teater==0 || teater>=4);

if(languages==1)
switch(teater)
{
case (1):
printf("\nAnda telah memilih GSC(Golden Screen Cinemas)\n");
printf("Sila tekan mana-mana kekunci untuk teruskan..");
getch();
break;
case (2):
printf("\nAnda telah memilih MBO(Malaysian Box Office)\n");
printf("Sila tekan mana-mana kekunci untuk teruskan..");
getch();
break;
case (3):
printf("\nAnda telah memilih Lotus Five Star\n");
printf("Sila tekan mana-mana kekunci untuk teruskan..");
getch();
break;

}

else
switch(teater)
{
case (1):
printf("\nYou have choosen GSC(Golden Screen Cinemas)\n");
printf("Press any key to continue..");
getch();
break;
case (2):
printf("\nYou have choosen MBO(Malaysian Box Office)\n");
printf("Press any key to continue..");
getch();
break;
case (3):
printf("\nYou have choosen Lotus Five Star\n");
printf("Press any key to continue..");
getch();
break;


}

do
{

if (languages==1)
{

printf("\n\n>Pilih Filem<\n");
}
else
{

printf("\n\n>Choose Movie<\n");
}
printf("\n1.Robocop");
printf("\n2.Endless Love");
printf("\n3.I,Frankstein\n");
scanf("\n%d",&movie);
}
while(movie==0 || movie>=4);

if(languages==1)
switch(movie)
{
case (1): printf("\nAnda telah memilih filem Robocop\n");
printf("Sila tekan mana-mana kekunci untuk teruskan..");
getch();
break;
case (2): printf("\nAnda telah memilih filem Endless Love\n");
printf("Sila tekan mana-mana kekunci untuk teruskan..");
getch();
break;
case (3): printf("\nAnda telah memilih filem I,Frankstein\n");
printf("Sila tekan mana-mana kekunci untuk teruskan..");
getch();
break;

}

else
switch (movie)
{
case (1): printf("\nYou have choosen Robocop\n");
printf("Press any key to continue..");
getch();
break;
case (2): printf("\nYou have choosen Endless Love\n");
printf("Press any key to continue..");
getch();
break;
case (3): printf("\nYou have choosen I,Frankstein\n");
printf("Press any key to continue..");
getch();
break;

}

do
{

if (languages==1)
{


printf("\n\n>Pilih Tayangan Masa<\n");
}
else
{


printf("\n\n>Choose Showtime<\n");
}
printf("\n1. 12.00 PM");
printf("\n2. 6.00 PM");
printf("\n3. 10.00 PM\n");
scanf("%d",&showtime);
}
while(showtime==0 || showtime>=4);

if (languages==1)
switch(showtime)
{
case(1): printf("\nAnda telah memilih tayangan masa anda pada pukul 12.00 PM\n");
printf("Sila tekan mana-mana kekunci untuk teruskan..");
getch();
break;
case(2): printf("\nAnda telah memilih tayangan masa anda pada pukul 6.00 PM\n");
printf("Sila tekan mana-mana kekunci untuk teruskan..");
getch();
break;
case(3): printf("\nAnda telah memilih tayangan masa anda pada pukul 10.00 PM\n");
printf("Sila tekan mana-mana kekunci untuk teruskan..");
getch();
break;


}

else
switch(showtime)
{
case(1): printf("\nYou have choosen 12.00 PM as your movie showtime\n");
printf("Press any key to continue..");
getch();
break;
case(2): printf("\nYou have choosen 6.00 PM as your movie showtime\n");
printf("Press any key to continue..");
getch();
break;
case(3): printf("\nYou have choosen 10.00 PM as your movie showtime\n");
printf("Press any key to continue..");
getch();
break;


}

if(languages==1)
{
printf("\n\n>Bilangan tempat duduk<\n");
printf("Dewasa : ");
scanf("%d",&seats);
printf("Kanak-kanak : ");
scanf("%d",&seats2);
jumlah=seats+seats2;
printf("Oleh itu,jumlah bilangan tempat duduk : %d Orang",jumlah);
printf("\nSila tekan mana-mana kekunci untuk teruskan..");
getch();
}

else
{
printf("\n\n>Number of booking seats<\n");
printf("Adult : ");
scanf("%d",&seats);
printf("Child : ");
scanf("%d",&seats2);
total2=seats+seats2;
printf("So,total number of booking seats : %d Person",total2);
printf("\nPress any key to continue..");
getch();
}



if (languages==1)
{

printf("\n\n>Harga<\n");
printf("\nDewasa = RM10.00");
printf("\nKanak-kanak = RM6.00");
printf("\nCukai Kerajaan = RM0.50");
total=(seats*10.00)+(seats2*6.00)+0.50;
printf("\nOleh itu,harga jumlah yang perlu dibayar ialah RM %.2f",total);
printf("\nSila tekan mana-mana kekunci untuk teruskan untuk melihat resit anda");
getch();
}
else
{
printf("\n\n>Payment<\n");
printf("\nAdult = RM10.00");
printf("\nChild = RM6.00");
printf("\nGoverment Tax = RM0.50");
total=(seats*10.00)+(seats2*6.00)+0.50;
printf("\nSo,the total amount that you have to pay is RM %.2f",total);
printf("\nPress any key to continue to booking for another");
getch();

}



getch();
return 0;

}
Topic archived. No new replies allowed.