Next
0 / 18
Module DEMO-32-91DEMO-C-32

Currency Converter using if

DEMO-C-32 โ€ข Programming in C

Browser-only practice

Problem Statement

Exchange rates:

  • 1 USD = 0.71 JOD
  • 1 USD = 0.92 EUR
  • 1 USD = 0.82 GBP

The conversion formula is:

Converted Amount = Amount in USD ร— Exchange Rate

The user will input:

  1. The amount in USD (a floating-point number)
  2. A number representing the target currency:
  • 1 for JOD
  • 2 for EUR
  • 3 for GBP

If the user selects an invalid option (not 1, 2, or 3), print INVALID OPTION.

Round the converted amount to two decimal places.

Input Format

The input consists of two lines:

  1. A floating-point number representing the amount in USD.
  2. An integer representing the target currency (1 for JOD, 2 for EUR, 3 for GBP).

Output Format

Print the converted amount with exactly two decimal places followed by the currency code (e.g., 71.00 JOD). If the option is invalid, print INVALID OPTION.

Sample Testcases

Submit runs every public testcase in this browser. Results and code never leave this device.

Sample #1
Public sample
100
2
92.00 EUR
Convert 100 USD to EUR: 100 ร— 0.92 = 92.00 EUR
Sample #2
Public sample
200
1
142.00 JOD
Convert 200 USD to JOD: 200 ร— 0.71 = 142.00 JOD
Sample #3
Public sample
75
3
61.50 GBP
Convert 75 USD to GBP: 75 ร— 0.82 = 61.50 GBP
Sample #4
Public sample
100
5
INVALID OPTION
Option 5 is not valid (1, 2, or 3 only).
Sample #5
Public sample
123.45
1
87.65 JOD
Convert 123.45 USD to JOD: 123.45 ร— 0.71 = 87.65 JOD

Web terminal

C, C++, Java, and Python run locally in a browser VM. No worker or visualizer is used.

Saved in this browser
Editor settings