Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Write a program to convert peso to dollar

+1 vote
asked Jul 29, 2018 by anonymous

1 Answer

0 votes
answered Jul 30, 2018 by anonymous
 #include<stdio.h>
   3:  #include<conio.h>
   4:   
   5:  float convert(float pesoValue, int choice, float amount);
   6:  void display(int choice, float result);
   7:   
   8:  int main()
   9:  {
  10:      int choice;
  11:      float pesoValue, amount, result = 0.0;
  12:   
  13:          printf("USD 1 is equivalent to Php ");
  14:          scanf("%f", &pesoValue);
  15:          printf("\nPress 1 for PESO to DOLLAR conversion\nPress 2 for DOLLAR to PESO conversion\n");
  16:       
 
  17:              while(1){
  18:                  printf("\nChoice: ");
  19:                  scanf("%d", &choice);
  20:                      if( choice == 0)
  21:                          return 0;
  22:                  printf("Amount: ");
  23:                  scanf("%f", &amount);
  24:                  result = convert(pesoValue, choice, amount);
  25:                  display(choice, result);
  26:              }
  27:           
  28:      getch();
  29:  }
  30:   
  31:  float convert(float pesoValue, int choice, float amount)
  32:  {
  33:      float result = 0.0;
  34:   
  35:          switch(choice){
  36:   
  37:              case 1:
  38:                  result = amount / pesoValue;
  39:                  break;
  40:              case 2:
  41:                  result = amount * pesoValue;
  42:                  break;
  43:              default:
  44:                  break;
  45:          }
  46:       
  47:      return result;
  48:  }
  49:   
  50:  void display(int choice, float result)
  51:  {
  52:      switch(choice){
  53:       
  54:          case 1:
  55:              printf(">USD %.2f\n", result); break;
  56:          case 2:
  57:              printf(">Php %.2f\n", result); break;
  58:          default:
  59:              printf(">Invalid Input\n");
  60:      }
  61:  }
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...