This is my code and i want to repeat my code until the user wants to exit.
--
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
again();
}
first()
{
char arjun;
printf("--------------------------------------------------\n");
printf("\n\tWould you like again to rent one?:\t\n");
printf("\t\tA for YES\n");
printf("\t\tB for NO\n");
printf("Select one:\t");
scanf("%s", &arjun);
if(arjun == 'B')
{
printf("\t\tThank You! Have a Nice Day!");
printf("--------------------------------------------------\n");
}
else if(arjun == 'A')
{
printf("\n");
again();
}
}
again()
{
char rent, choose, select;
float old = 500;
float medium = 1000;
float mega = 2000;
float luxury = 5000;
float stars = 10000;
float paid;
float hours;
printf("\n\t\t---**Boat For Rent**--\n");
printf("[1]\tOld Boat\tP500\tper hour\n");
printf("[2]\tMedium Boat\tP1,000\tper hour\n");
printf("[3]\tMega Boat\tP2,000\tper hour\n");
printf("[4]\tLuxury Boat\tP5,000\tper hour\n");
printf("[5]\t5 Stars Boat\tP10,000\tper hour\n\n");
printf("--------------------------------------------------\n");
printf("Would you like to rent one?:\t\n");
printf("\t(Y) for YES\n");
printf("\t(N) for NO\n");
printf("Choose one:\t");
scanf("%c", &rent);
if(rent == 'Y')
{
printf("What particular boat would you like to rent?:\t");
scanf("%s", &choose);
}
else if(rent == 'N')
{
printf("\tThank You! Have a Good Day!");
}
switch(choose)
{
case '1':
printf("--------------------------------------------------\n");
printf("What kind of Transaction?:\t\n");
printf("[C]cash\n");
printf("[H]hours\n");
printf("Choose One please:\t");
scanf("%s", &select);
if(select == 'C')
{
printf("--------------------------------------------------\n");
printf("Enter Your Money:\t");
scanf("%f", &paid);
hours = paid / old;
printf("You only have %.2f hour(s)\n", hours);
first();
}
else if(select == 'H')
{
printf("--------------------------------------------------\n");
printf("For how many hours would you like to use?:\t");
scanf("%f", &hours);
paid = hours * old;
printf("Your Total Payment is %.2f\n", paid);
first();
}
break;
case '2':
printf("--------------------------------------------------\n");
printf("What kind of Transaction?:\t\n");
printf("[C]cash\n");
printf("[H]hours\n");
printf("Choose One please:\t");
scanf("%s", &select);
if(select == 'C')
{
printf("--------------------------------------------------\n");
printf("Enter Your Money:\t");
scanf("%f", &paid);
hours = paid / medium;
printf("You only have %.2f hour(s)\n", hours);
first();
}
else if(select == 'H')
{
printf("--------------------------------------------------\n");
printf("For how many hours would you like to use?:\t");
scanf("%f", &hours);
paid = hours * medium;
printf("Your Total Payment is %.2f\n", paid);
first();
}
break;
case '3':
printf("--------------------------------------------------\n");
printf("What kind of Transaction?:\t\n");
printf("[C]cash\n");
printf("[H]hours\n");
printf("Choose One please:\t");
scanf("%s", &select);
if(select == 'C')
{
printf("--------------------------------------------------\n");
printf("Enter Your Money:\t");
scanf("%f", &paid);
hours = paid / mega;
printf("You only have %.2f hour(s)\n", hours);
first();
}
else if(select == 'H')
{
printf("--------------------------------------------------\n");
printf("For how many hours would you like to use?:\t");
scanf("%f", &hours);
paid = hours * mega;
printf("Your Total Payment is %.2f\n", paid);
first();
}
break;
case '4':
printf("--------------------------------------------------\n");
printf("What kind of Transaction?:\t\n");
printf("[C]cash\n");
printf("[H]hours\n");
printf("Choose One please:\t");
scanf("%s", &select);
if(select == 'C')
{
printf("--------------------------------------------------\n");
printf("Enter Your Money:\t");
scanf("%f", &paid);
hours = paid / luxury;
printf("You only have %.2f hour(s)\n", hours);
first();
}
else if(select == 'H')
{
printf("--------------------------------------------------\n");
printf("For how many hours would you like to use?:\t");
scanf("%f", &hours);
paid = hours * luxury;
printf("Your Total Payment is %.2f\n", paid);
first();
}
break;
case '5':
printf("--------------------------------------------------\n");
printf("What kind of Transaction?:\t\n");
printf("[C]cash\n");
printf("[H]hours\n");
printf("Choose One please:\t");
scanf("%s", &select);
if(select == 'C')
{
printf("--------------------------------------------------\n");
printf("Enter Your Money:\t");
scanf("%f", &paid);
hours = paid / stars;
printf("You only have %.2f hour(s)\n", hours);
first();
}
else if(select == 'H')
{
printf("--------------------------------------------------\n");
printf("For how many hours would you like to use?:\t");
scanf("%f", &hours);
paid = hours * stars;
printf("Your Total Payment is %.2f\n", paid);
first();
}
break;
}
return 0;
}