I Having Problems with my program. I hope someone will help me with my problems.
By the way, I need help regarding Going Back to Menu using Loop.
Thank you very much!

if you have seen any problems, please post your message. Thanks!

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


   float usd, php, jpy, bad, gbp, sar, cyn, sfk, hkd, aud, cad, eur;
   char mchoice, choice; 
   int pchoice;
   clrscr();
   gotoxy(33,1);
   start:
   printf("\nCurrency Converter\n");
   printf("================================================================================");
   printf("Please select your choice: \n");
   printf("[a] Preffered Convertible Currency to PHP\n");
   printf("[b] USD to All Currencies\n");
   printf("[c] PHP to Preffered Currency\n");
   printf("[d] PHP to All Currencies\n");
   printf("[e] About the Program\n");
   printf("[x] Exit the Program\n");
   printf("Please enter you choice: ");
   scanf("%c",&mchoice);

switch (mchoice)

case 'a':
case 'A':
{  
   printf("\n1. USD to PHP\n");
   printf("2. JPY to PHP\n");
   printf("3. BAH to PHP\n");
   printf("4. GBP to PHP\n");
   printf("5. SAR to PHP\n");
   printf("6. AUD to PHP\n");
   printf("7. Euro to PHP\n");
   printf("8. CYN to PHP\n");
   printf("9. HKD to PHP\n");
   printf("10. SFC to PHP\n");

   printf("Please Enter Your Preffered Currency Conversion From The Menu: \t");
   scanf("%d",&choice);

	switch(choice)
{
         case 1:

	 printf("\n\nUSD to PHP:\n\n");
         printf("Please Enter USD Amount to be Converted: \t");
         scanf("%f",&usd);
	 printf("\n%.2f US Dollars is equal to %.2f Pesos",usd ,usd * 44.24);
         getch();
         clrscr();
         goto start;
     


         case 2:

	  printf("\n\nJPY to PHP:\n\n");
          printf("Please Enter Japan Yen to be Converted: \t");
          scanf("%f",&jpy);
          printf("\n%.2f Japan Yen is equal to %.2f Pesos",jpy ,jpy * 0.576);
          break;



	 case 3:

	 printf("\n\Bahrain Dinar to PHP:\n\n");
         printf("Please Enter BAH Amount to be Converted: \t");
         scanf("%f",&bad);
         printf("\n%.2f Bahrain Dinar is equal to %.2f Pesos",bad ,bad * 117.4007);
        break;




	 case 4:

	 printf("\n\nGBP to PHP:\n\n");
         printf("Please Enter UK Pounds Amount to be Converted: \t");
         scanf("%f",&gbp);
         printf("\n%.2f UK Pounds is equal to %.2f Pesos",gbp ,gbp * 68.41);
         break;


	case 5:

	printf("\n\nSAR to PHP:\n\n");
        printf("Please Enter SAR Amount to be Converted: \t");
        scanf("%f",&sar);
        printf("\n%.2f Saudi Arabian Rial is equal to %.2f Pesos",sar ,sar * 11.78);
	break;

         case 6:

	 printf("\n\nAUD to PHP:\n\n");
         printf("Please Enter AUD Amount to be Converted: \t");
         scanf("%f",&aud);
	 printf("\n%.2f Australian Dollars is equal to %.2f Pesos",aud ,aud * 45.2991);
         break;


	case 7:

	 printf("\n\nEUR to PHP:\n\n");
         printf("Please Enter Euro Amount to be Converted: \t");
         scanf("%f",&eur);
	 printf("\n%.2f Euros is equal to %.2f Pesos",eur ,eur * 56.4933);
         break;

	case 8:
         
	 printf("\n\nCYN to PHP:\n\n");
         printf("Please Enter China Yuan Amount to be Converted: \t");
         scanf("%f",&cyn);
	 printf("\n%.2f China Yuan is equal to %.2f Pesos",cyn ,cyn * 7.0069);
        break;

        case 9:
         
	 printf("\n\nHKD to PHP:\n\n");
         printf("Please Enter HKD Amount to be Converted: \t");
         scanf("%f",&hkd);
	 printf("\n%.2f US Dollars is equal to %.2f Pesos",hkd ,hkd * 5.6979);
         break;
       
         case 10:
         
	 printf("\n\nSFK to PHP:\n\n");
         printf("Please Enter SFK Amount to be Converted: \t");
	 scanf("%f",&sfk);
	 printf("\n%.2f Swiss Francs is equal to %.2f Pesos",sfk ,sfk * 46.5894);
         break;
            
}

    
case 'b':
   
    printf("Please enter the US Dollar Amount: ");
    scanf("%f", &usd);
    printf("\n\nHere's the Conversion of US Dollar to Other Currencies:\n\n");
    printf("\nJapanese Yen (JPY): %2.f",usd * 0.013);
    printf("\nGreat Britain Pound (GBP): %.2f",usd * 1.546);
    printf("\nBahrain Dinar: %.2f",usd * 117.4007);
    printf("\nSaudi Arabian Rial (SAR): %.2f",usd * 0.266);
    printf("\nAustralian Dollars: %.2f",usd * 45.2991);
    printf("\nEuros: %.2f",usd * 56.4933);
    printf("\nChina Yuan: %.2f",usd * 7.0069);
    printf("\nHong Kong Dollars: %.2f",usd * 5.6979);
    printf("\nSwiss Francs: %.2f",usd * 46.5894);
    



case 'c':

   printf("\n[1]. PHP to USD\n");
   printf("[2]. PHP to JPY\n");
   printf("[3]. PHP to BAH\n");
   printf("[4]. PHP to GBP\n");
   printf("[5]. PHP to SAR\n");
   printf("[6]. PHP to AUD\n");
   printf("[7]. PHP to Euro\n");
   printf("[8]. PHP to CYN\n");
   printf("[9]. PHP to HKD\n");
   printf("[10].PHP to SFC\n");

   printf("Please Enter Your Preffered Currency Conversion From The Menu: \t");
   scanf("%d",&pchoice);


switch(pchoice)
{
      case 1:
      printf("\n\nPHP to USD:\n\n");
      printf("Please Enter PHP Amount to be Converted: \t");
      scanf("%f",&php);
      printf("\n%2f Pesos is equal to %.2f US Dollars",php, php / 44.24);
    
     case 2:
      printf("\n\nPHP to JPY:\n\n");
      printf("Please Enter PHP Amount to be Converted: \t");
      scanf("%f",&php);
      printf("\n%2f Pesos is equal to %.2f Japan Yen",php, php / 0.576);
 
 
     case 3:
      
      printf("\n\PHP to Bahrain Dinar:\n\n");
         printf("Please Enter PHP Amount to be Converted: \t");
         scanf("%f",&php);
         printf("\n%.2f Pesos is equal to %.2f Bahrain Dinar",php ,php / 117.4007);
     
      

     case 4:
      printf("\n\nPHP to GBP:\n\n");
         printf("Please Enter PHP Amount to be Converted: \t");
         scanf("%f",&php);
         printf("\n%.2f Pesos is equal to %.2f UK Pounds",php ,php / 68.41);
     

    case 5:
     
      printf("\n\nPHP to SAR:\n\n");
        printf("Please Enter PHP Amount to be Converted: \t");
        scanf("%f",&php);
        printf("\n%.2f Pesos is equal to %.2f Saudi Arabian Rial",php, php / 11.78);
      

   case 6:

      printf("\n\nPHP to AUD:\n\n");
         printf("Please Enter PHP Amount to be Converted: \t");
         scanf("%f",&php);
	 printf("\n%.2f Pesos is equal to %.2f Australian Dollars",php, php / 45.2991);
        

    case  7:

      printf("\n\nEPHP to EUR:\n\n");
         printf("Please Enter PHP Amount to be Converted: \t");
         scanf("%f",&php);
	 printf("\n%.2f Pesos is equal to %.2f Euros",php, php / 56.4933);
        

    case 8:

      printf("\n\nPHP to CYN:\n\n");
         printf("Please Enter PHP Amount to be Converted: \t");
         scanf("%f",&php);
	 printf("\n%.2f Pesos is equal to %.2f China Yuan",cyn ,cyn / 7.0069);
       

   case 9:
      printf("\n\nPHP to HKD:\n\n");
         printf("Please Enter PHP Amount to be Converted: \t");
         scanf("%f",&php);
	 printf("\n%.2f Pesos is equal to %.2f Hong Kong Dollars",php, php / 5.6979);
        
	case 10:
      printf("\n\nSFK to PHP:\n\n");
         printf("Please Enter PHP Amount to be Converted: \t");
	    scanf("%f",&php);
	 printf("\n%.2f Pesos is equal to %.2f Swiss Francs",php, php / 46.5894);
  
    default: printf("Wrong Input!");
    getch();
    clrscr();
     goto start;
   }  
case 'd':
    
    printf("\nPlease enter the Philippine Peso Amount: ");
    scanf("%f", &php);
    printf("\n\nHere's the Conversion of Philippine Peso to Other Currencies:\n\n");
    printf("\nJapanese Yen (JPY): %.2f",php / 0.013);
    printf("\nGreat Britain Pound (GBP): %.2f",php / 1.546);
    printf("\nBahrain Dinar: %2f",php ,php / 117.4007);
    printf("\nSaudi Arabian Rial (SAR): %.2f",php / 0.266);
    printf("\nAustralian Dollars: %.2f",php/ 45.2991);
    printf("\nEuros: %.2f",php / 56.4933);
    printf("\nChina Yuan: %.2f",php / 7.0069);
    printf("\nHong Kong Dollars: %.2f",php / 5.6979);
    printf("\nSwiss Francs: %.2f",php / 46.5894);

case 'x':
printf("The program will now terminate! Bye Bye!");
getch();
return 0;

default: printf("Wrong Input!");
getch();
clrscr();
goto start;

}
getch();
}

Recommended Answers

All 7 Replies

Put your menu in a function.
Put all of those options in functions, then call them once the user has entered the correct option.

You can then get rid of the "goto" statements and the program will be easier to manage.

you are using getch(), clrscr() all of which are part of <conio.h> which you haven't included. It is also suggested not to use <conio.h> as it is not standard and not supported in many compilers.

You are returning 0 in line 272, but your main function's return type is void. Avoid it.

As said in the previous post, avoid using goto statements too.

Don't forget to include break; in your cases otherwise it will continue to run the statements case after case

Thanks to all of your suggestions and corrections!
I will apply all of those!

By the way @thines01, How to put the menu in function? I'm sorry, I don't know how to do that.

Here's an example

/*menu function*/
int menu(int *choice){
    //here are the codes for the menu
return choice;
}

/*main function*/
int main(void){
    int choice;
    menu(&choice);
    .
    .
    .
    return 0
}

note: there are a lot of ways to initialize a function
Try to read about how to use and create functions in c, there are tons of articles about that on the web

Yes, and somethng like this:

#include <stdio.h>

void Menu()
{
   printf(
      "\nCurrency Converter\n"
      "========================================"
      "========================================"
      "Please select your choice: \n"
      "[a] Preffered Convertible Currency to PHP\n"
      "[b] USD to All Currencies\n"
      "[c] PHP to Preffered Currency\n"
      "[d] PHP to All Currencies\n"
      "[e] About the Program\n"
      "[x] Exit the Program\n"
      "Please enter you choice: ");
}
int main(void)
{
   int mChoice = 0;
   do
   {
      Menu();
      scanf("%c", &mChoice);
   } while('x' != mChoice);

   return 0;
}

Wow! it works! Thanks to all of you who help me!
Actually this is my School Project and I'm having a hard time solving my programs problem!

Thank you very much to all of you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.