<java>ce deux prg donne pas même resultat

Fermé
domxaline Messages postés 188 Date d'inscription lundi 16 mai 2005 Statut Membre Dernière intervention 7 mars 2018 - 2 juil. 2010 à 14:52
 domxaline - 2 juil. 2010 à 22:14
Bonjour,
les deux prg suivants donne pas même résultat,aidez moi s'il vous plaît


public class Countchange 
{
	public static void main(String[] args)
    {
		int quarters;
		int dimes;
		int nickles;
		int pennies;
		double dollars;
		double total;
		
		TextIO.put("Enter the number of quarters:");
		quarters=TextIO.getInt();
		TextIO.put("Enter the number of dimes:");
		dimes=TextIO.getInt();
		TextIO.put("Enter the number of nickles:");
		nickles=TextIO.getInt();
		TextIO.put("Enter the number of pennies");
		pennies=TextIO.getInt();
		
		dollars=(0.25*quarters)+(0.10*dimes)+(0.05*nickles)+(0.01*pennies);
		
		total=dollars/100.0;
		TextIO.putln();
		TextIO.putln("The total in dollars is "+dollars);
			
    }
}

resultat ce ce prg:
Enter the number of quarters:1
Enter the number of dimes:? 2
Enter the number of nickles:? 3
Enter the number of pennies? 4


The total in dollars is 0.6400000000000001

import java.util.Scanner;
public class Euros 
 {
	public static void main(String []args)
	{
		int vingtcinq=0;
		int cinquante=0;
		int dix=0;
		int cinq=0;
		double euro=0;
		double total;
		
		System.out.println("Entrez pour vingtcinq");
		Scanner sc=new Scanner(System.in);
		vingtcinq=sc.nextInt();
		
		System.out.println("Entrez pour cinquante");
		Scanner sc1=new Scanner(System.in);
		vingtcinq=sc1.nextInt();
		
		System.out.println("Entrez pour dix");
		Scanner sc2=new Scanner(System.in);
		vingtcinq=sc2.nextInt();
		
		System.out.println("Entrez pour cinq");
		Scanner sc3=new Scanner(System.in);
		vingtcinq=sc3.nextInt();
		
		euro=(0.25*vingtcinq)+(0.50*cinquante)+(0.10*dix)+(0.05*cinq);
		total=euro/100.0;
		System.out.println("The total en euros "+total);
	}
 }

resultat ce ce prg:
Entrez pour vingtcinq
1
Entrez pour cinquante
2
Entrez pour dix
3
Entrez pour cinq
4
The total en euros 0.01


je veux il additionne
vingtcinq*1;cinquante*2;dix*3;cinq*4
et il divise ce montant par 100
et affiche résultat
A voir également:

3 réponses

poukkid Messages postés 106 Date d'inscription mercredi 20 mai 2009 Statut Membre Dernière intervention 11 avril 2012 11
2 juil. 2010 à 15:36
Salut,

Ton problème vient simplement du fait que tuas oublié de changer tes variables : tu utilises toujours la variable vingtcinq...

Attention avec les copié-collé....

System.out.println("Entrez pour vingtcinq");
Scanner sc=new Scanner(System.in);
vingtcinq=sc.nextInt();

System.out.println("Entrez pour cinquante");
Scanner sc1=new Scanner(System.in);
vingtcinq=sc1.nextInt();

System.out.println("Entrez pour dix");
Scanner sc2=new Scanner(System.in);
vingtcinq=sc2.nextInt();

System.out.println("Entrez pour cinq");
Scanner sc3=new Scanner(System.in);
vingtcinq=sc3.nextInt();
0
le résultat de class Countchange
The total in dollars is 0.6400000000000001

le résultat pour le class Euros
The total en euros 0.0175

les réponse n'est pas le même pour les 2 prgs !!!
c'est pas normal
0
merci beaucoup j'ai corrigé mon erreur

il faut écrire comme ceci:
package Textprg;

public class Countchange 
{
	public static void main(String[] args)
    {
		int quarters;
		int fifty;
		int dimes;
		int nickles;
		
		double dollars;
		double total;
		
		TextIO.put("Enter the number of quarters:");
		quarters=TextIO.getlnInt();
		TextIO.put("Enter the number of pennies:");
		fifty=TextIO.getlnInt();
		TextIO.put("Enter the number of dimes:");
		dimes=TextIO.getlnInt();
		TextIO.put("Enter the number of nickles:");
		nickles=TextIO.getlnInt();
		
		
		//dollars=(0.25*quarters)+(0.10*dimes)+(0.05*nickles)+(0.01*pennies);
		dollars=(0.25*quarters)+(0.50*fifty)+(0.10*dimes)+(0.05*nickles);
		total=dollars/100.0;
		TextIO.putln();
		TextIO.putln("The total in dollars is "+total);
		
		
    }
}

0