0
準備製作一個程序,詢問1到5之間的票數。 然後我需要知道每張票的獎品,要求用戶放置它。 然後做總數的總和。用戶如何選擇多張門票,然後要求每張門票的總獎金總額?
//kb = keyboard, t = tickets, val = prize, sm = sum tickets
Scanner kb = new Scanner(System.in);
int t = 0;
double val = 0,sm = 0;
//this is a loop just for know the ticket number.
do {
System.out.print("How many tickets do you have?[max 5]");
while(!kb.hasNextInt()){
kb.nextLine();
System.out.println("This is not valid, try again.");
}
t = kb.nextInt();
} while ((t <= 0 || t >= 6));
的問題還是我卡住就在這裏。(它需要的是與)
//With the for I can ask for the value of each ticket
for (int i = 1; i<=t ;i++) {
System.out.println("Ticket número "+i+" es de:");
val = kb.nextDouble();
}
如何我總結了diffents每張票的獎金,使總金額?
只要每個'val'添加到'sm',在循環內:'SM = SM + VAL;' 。 – Blorgbeard