Question

While Loop - $100! 36 36 unread replies. 36 36 replies. Create a program that uses...

While Loop - $100! 36 36 unread replies. 36 36 replies. Create a program that uses a while loop that asks the user to input $ amounts over and over until the the accumulated amount exceeds $100. At that point give a congratulatory message.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE: Done in java

import java.util.Scanner;

public class Dollars {

public static void main(String[] args) {

int dollars = 0;// the dollars initially

int input;// user input variable

Scanner scan = new Scanner(System.in);// instantiating the scanner class

while(dollars <= 100) {//the while loop

input = scan.nextInt();//getting the input

dollars += input;

}

// the congratulatory message

System.out.println("Congrats!You have accummulated 100 dollars!!!");

System.exit(0);

}

}

OUTPUT:

45 54 Congrats!You have accummulated 100 dollars!!!

9 1 2 98 Congrats !You have accummulated 100 dollars!!!

Add a comment
Know the answer?
Add Answer to:
While Loop - $100! 36 36 unread replies. 36 36 replies. Create a program that uses...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Python Exercise – For & While Loops Create a new file called loops.py and use...

    In Python Exercise – For & While Loops Create a new file called loops.py and use it for all parts of this exercise. Remember the difference between input and raw input? Be sure to test your code for each part before moving on to the next part. Write a program using a for loop that calculates exponentials. Your program should ask the user for a base base and an exponent exp, and calculate baseexp. Write a program using a while...

  • Write a program that incorporates these functions and statements: • list • while loop • for...

    Write a program that incorporates these functions and statements: • list • while loop • for loop • if • print() • input() • concatenation This program must create a grocery shopping list based on the user input • the program will ask a user to enter a new grocery item until the user presses Enter • then all user input will be added to a list • then the list with all grocery items will be printed

  • USE of C++ please Write a program that achieves the following requirements: 1. A while/do-While loop...

    USE of C++ please Write a program that achieves the following requirements: 1. A while/do-While loop that will ask the user to input an integer on each iteration. The loop keeps a running total of the input and exits only when the total exceeds the first input times 10. 2. A for loop that does the exact same thing. The program should print out the *new* total each time the total is input.

  • Please create a java program and use a do/while loop to check for the correct password...

    Please create a java program and use a do/while loop to check for the correct password entered by the student. The password should be your initials and 2020Mar23. For example, my password would be "TJC2020Mar23". If the user has not entered the correct password after 3 attempts, they should receive a message to that effect and they should not be allowed any further attempts.

  • a) Write a program that uses a while loop to print all divisors of a number...

    a) Write a program that uses a while loop to print all divisors of a number supplied by the user. The program should also print the sum of all the divisors and whether the number the user entered is a prime number or not. Note: The definition of a divisor is a number that divides another evenly (i.e., without a remainder) and the definition of a prime number is a number whose only divisors are 1 and itself. b) Implement...

  • python program 6 Write an input validation loop that asks the user to enter a number...

    python program 6 Write an input validation loop that asks the user to enter a number in the range of 100 through 1000? 7 Write an input validation loop that asks the user to enter ‘Y’, ‘y’, ‘N’, or ‘n’? 8 How many times the following loop will repeat? cnt = 0    while  cnt != 5: print(cnt) cnt = cnt + 2

  • Write a java program that makes use of the ‘DO WHILE ’ loop. The program asks...

    Write a java program that makes use of the ‘DO WHILE ’ loop. The program asks a user to enter information about several of their friends. The information is their last name, the state they live in, their age, and their expected graduation year. After you enter one friend, write out each individually. You must use JOptionPane to input the 4 fields, and to output the 4 fields. Refer to the textbook Code Listing 4-6 to see how to use...

  • Assignment (Must be completed and submitted prior to your lab3 session) Create a do-while loop that...

    Assignment (Must be completed and submitted prior to your lab3 session) Create a do-while loop that displays a random number on the screen, and then displays a message (in a new line) asking the user if he wishes to see another random number. If the user responds with a 'y' or a ‘Y' character, then the program shall repeat (i.e. outputs another random number and asks the user again). If the user responds with HINTS: To generate a random number...

  • java program QUESTION 2: 1. Write a do-while loop that asks the user to select a...

    java program QUESTION 2: 1. Write a do-while loop that asks the user to select a task from the following menu to continue: 1. Option 1 2. Option 2 3. Option 3 4. Option 4 5. Exit Read the selection from the keyboard then write the switch statement: For option 1, display the message "Do the option 1" For option 2, display the message "Do the option 2" For option 3, display the message "Do the option 3" For option...

  • Objectives: Use the while loop in a program Use the do-while loop in a second program...

    Objectives: Use the while loop in a program Use the do-while loop in a second program Use the for loop in a third program Instructions: Part A. Code a for loop to print the Celsius temperatures for Fahrenheit temperatures 25 to 125. C = 5/9(F – 32).Output should be in a table format: Fahrenheit Celsius 25 ? . . . . . . . . Turn in the source and the output from Part A. Part B. Code a while...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT