Question

// TODO code application logic here //Question 1: Currency conversion // Write some code that first...

// TODO code application logic here
//Question 1: Currency conversion
// Write some code that first asks the user to type the current
// conversion rate for 1 U.S. Dollar (USD) to 1 Euro. Next, in a while
// loop, ask users for an amount in USD, read it in, and convert it to
// Euro, printing as you go. Use 0 as a sentinel (i.e.: a signal to
// stop the loop).
// Here's a sample run:
// Whats the current conversion rate for 1 USD to 1 Euro:
// .85
// Enter an amount in USD:
// 10.0
// 10.0 in USD is equal to 8.5 Euro
// Enter an amount in USD:
// 2.0
// 2.0 in USD is equal to 1.7 Euro
// Enter an amount in USD:
// 0
// Quitting...
  

*******In Java*********

Homework Answers

Answer #1

Explanation:

here is the code which creates a scanner object and asks for the conversion rate first.

Then it asks for the amount again and again and keeps converting it using the conversion rate until 0 is entered.

Code:


import java.util.Scanner;

public class Main
{
   public static void main(String[] args) {
  
   Scanner sc = new Scanner(System.in);
  
       System.out.println("Whats the current conversion rate for 1 USD to 1 Euro: ");
       double conversion = sc.nextDouble();
      
      
       while(true)
       {
       System.out.println("Enter an amount in USD: ");
       double usd = sc.nextDouble();
      
       if(usd==0)
       {
       System.out.println("Quitting..");
       break;
       }
      
       System.out.println(usd+" in USD is equal to "+(usd*conversion)+" Euro");
       }
      
      
      
      
   }
}

Output:

PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!

PLEASE COMMENT IF YOU NEED ANY HELP!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT