This question already has an answer here:
I just started to teach myself how program today. So far my first three programs worked well but I wanted to create a more advanced version of the currency converter program I had written.
What I want to do is to ask for the amount in US currency and then ask for the currency it should be exchanged for and return the correct value based on the currency chosen.
//Currency v1.2 By: Deranged Hermit
import java.util.Scanner;
public class Currency {
public static void main(String[] args) {
System.out.println("Enter your dollar amount:");
Scanner dollarAmount = new Scanner(System.in);
double dollar, total;
dollar = dollarAmount.nextDouble();
System.out.println("Enter currency type you would like to convert to.");
Scanner currencyType = new Scanner(System.in);
String type;
type = currencyType.next();
if (type.equalsIgnoreCase("yen"))
x = 106.24;
System.out.println(total + " Yen");
else if (type.equalsIgnoreCase("pounds"))
x = .76;
System.out.println(total + " Pounds");
else if (type.equalsIgnoreCase("rubles"))
x = 63.3;
System.out.println(total + " Rubles");
else
System.out.println("You have entered an invalid currency");
// Equations for currency
total = dollar * x;
}
}
I have three errors.
First x = 106.24; says that it can not find the symbol variable x. But this is were I am trying to define x.
Second, all of the else if statements are saying that they are else without the if, however both else and if are blue in netbeans
Finally, when defining total it says that x is never used. I think this will clear up as soon as I resolve the first issue.
Aucun commentaire:
Enregistrer un commentaire