do while/looping help!

Im having trouble adding the looping in my program. I have here like an MRT ticketing machine but I don't know how to add the looping.
Can someone help me, Im thinking of adding an an option here:
___________________________________________________________________________
if(c2 == 2)
{printf("\nTo Avail a Ticket going to Quezon Avenue,\nPlease insert Php10.00\n");
printf("Enter Amount: ");
scanf("%d", & n2);
system("pause");
if(n2==10)
printf("Printing TICKET");
else
printf("Error");}
----------------------------------------------------------------------------
where if the user inputs a different integer and will result to printing "Error", another option will pop out asking the user if he wants to try again

example:
Enter Amount: 11
Press any key to continue...
Error
Would you like to try again?(y/n):

*if the user inputs y, he will go back from the start, and if he inputs n,the program will end. But if that doesn't work, any other suggestions is welcome and also how to do it. Thanks!

BTW THE WHOLE CODES WON'T FIT HERE SO I CUT IT.



Codes:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define SIZE 5
int choice1, c2;
int n2,n3,n4,n5,n6,n7,n8,n9,n10;
int q1,q3,q4,q5,q6,q7,q8,q9,q10;
int k1,k2,k4,k5,k6,k7,k8,k9,k10;
int c1,c2,c3,c5,c6,c7,c8,c9,c10;
int san1,san2,san3,san4,san6,san7,san8,san9,san10;
int o1,o2,o3,o4,o5,o7,o8,o9,o10;
int sha1,sha2,sha3,sha4,sha5,sha6,sha8,sha9,sha10;
int bo1,bo2,bo3,bo4,bo5,bo6,bo7,bo9,bo10;
int g1,g2,g3,g4,g5,g6,g7,g8,g10;
int bu1,bu2,bu3,bu4,bu5,bu6,bu7,bu8,bu9;

void info(){
printf("M R T T I C K E T V E N D I N G M A C H I N E\n");
printf("\n**How to Buy a Ticket:\n");
printf("[1] Choose From What Station. \n");
printf("[2] Choose Destination. \n");
printf("[3] Insert EXACT amount needed.\n");
printf("[4] Get your ticket.\n");

printf("\n\n\t\t\t!!!NOTE!!!\nThis Machine is a One(1) Transaction at a Time ONLY. ");}

int main(){
info();

printf("\n\n=============================================================\n");
printf("|| Choose From What Station | Price ||\n");
printf("=============================================================\n");
printf("|| [ 1] North Ave | [ 1] North Ave: Php -- ||\n");
printf("|| [ 2] Quezon Ave | [ 2] Quezon Ave: Php -- ||\n");
printf("|| [ 3] Kamuning | [ 3] Kamuning: Php -- ||\n");
printf("|| [ 4] Cubao | [ 4] Cubao: Php -- ||\n");
printf("|| [ 5] Santolan | [ 5] Santolan: Php -- ||\n");
printf("|| [ 6] Ortigas | [ 6] Ortigas: Php -- ||\n");
printf("|| [ 7] Shaw | [ 7] Shaw: Php -- ||\n");
printf("|| [ 8] Boni | [ 8] Boni: Php -- ||\n");
printf("|| [ 9] Guadalupe | [ 9] Guadalupe: Php -- ||\n");
printf("|| [10] Buendia | [10] Buendia: Php -- ||\n");
printf("=============================================================\n");
printf("Enter number: ");
scanf("%d", &choice1);

switch(choice1){
{case 1:
{system("cls");
info();
printf("\n\n=============================================================\n");
printf("|| Choose Destination | Price ||\n");
printf("=============================================================\n");
printf("|| [ 1] North Ave | [ 1] North Ave: Php -- ||\n");
printf("|| [ 2] Quezon Ave | [ 2] Quezon Ave: Php 10 ||\n");
printf("|| [ 3] Kamuning | [ 3] Kamuning: Php 12 ||\n");
printf("|| [ 4] Cubao | [ 4] Cubao: Php 14 ||\n");
printf("|| [ 5] Santolan | [ 5] Santolan: Php 16 ||\n");
printf("|| [ 6] Ortigas | [ 6] Ortigas: Php 18 ||\n");
printf("|| [ 7] Shaw | [ 7] Shaw: Php 20 ||\n");
printf("|| [ 8] Boni | [ 8] Boni: Php 22 ||\n");
printf("|| [ 9] Guadalupe | [ 9] Guadalupe: Php 24 ||\n");
printf("|| [10] Buendia | [10] Buendia: Php 26 ||\n");
printf("=============================================================\n");
printf("Enter Number of Destination: ");
scanf("%d", &c2);


if(c2 == 2)
{printf("\nTo Avail a Ticket going to Quezon Avenue,\nPlease insert Php10.00\n");
printf("Enter Amount: ");
scanf("%d", & n2);
system("pause");
if(n2==10)
printf("Printing TICKET");
else
printf("Error");}



else if(c2 == 3)
{printf("\nTo Avail a Ticket going to Kamuning Station,\nPlease insert Php12.00\n");
printf("Enter Amount: ");
scanf("%d", & n3);
system("pause");
if(n3==12)
printf("Printing TICKET");
else
printf("Error");}


else if(c2 == 4)
{printf("\nTo Avail a Ticket going to Cubao Station,\nPlease insert Php14.00\n");
printf("Enter Amount: ");
scanf("%d", & n4);
system("pause");
if(n4==14)
printf("Printing TICKET");
else
printf("Error");}


else if(c2 == 5)
{printf("\nTo Avail a Ticket going to Santolan Station,\nPlease insert Php16.00\n");
printf("Enter Amount: ");
scanf("%d", & n5);
system("pause");
if(n5==16)
printf("Printing TICKET");
else
printf("Error");}


else if(c2 == 6)
{printf("\nTo Avail a Ticket going to Ortigas Station,\nPlease insert Php18.00\n");
printf("Enter Amount: ");
scanf("%d", & n6);
system("pause");
if(n6==18)
printf("Printing TICKET");
else
printf("Error");}


else if(c2 == 7)
{printf("\nTo Avail a Ticket going to Shaw Blvd,\nPlease insert Php20.00\n");
printf("Enter Amount: ");
scanf("%d", & n7);
system("pause");
if(n7==20)
printf("Printing TICKET");
else
printf("Error");}


else if(c2 == 8)
{printf("\nTo Avail a Ticket going to Boni Station,\nPlease insert Php22.00\n");
printf("Enter Amount: ");
scanf("%d", & n8);
system("pause");
if(n8==22)
printf("Printing TICKET");
else
printf("Error");}


else if(c2 == 9)
{printf("\nTo Avail a Ticket going to Guadalupe Station,\nPlease insert Php24.00\n");
printf("Enter Amount: ");
scanf("%d", & n9);
system("pause");
if(n9==24)
printf("Printing TICKET");
else
printf("Error");}


else if(c2 == 10)
{printf("\nTo Avail a Ticket going to Buendia Station,\nPlease insert Php26.00\n");
printf("Enter Amount: ");
scanf("%d", & n10);
system("pause");
if(n10==26)
printf("Printing TICKET");
else
printf("Error");}
getch();break; }
first, use code tags [\code]. and if you want to do a loop just do this:
1
2
3
4
5
6
7
8
9
char yn
while(1<2) {
    printf("Do you want to try again?");
    scanf("%d", yn);
    if (yn != "y") {
        exit();
    }
    /**and start over*/
}
Filipino. :) :) :)

yohohohoho..

Read a lot about do-while loop, or goto loops. :) There are a lot here kapatid.
Topic archived. No new replies allowed.