Penny=Penny - (Dime*10) # Printing the Dollars,Quarter, Dime, Penny if Penny <= 0: What's wrong with this expression? print('No change')

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter8: Arrays And Strings
Section: Chapter Questions
Problem 10PE
icon
Related questions
Question
100%

What's wrong with line 18, 19 in the code in the screenshot attached. Attempting to check zero, or negative input by the user. Thanks

# Asking user input in pennies
1
>
Penny = int(input("Enter pennies: "))
>
3
# Finding the number of Dollars
> ullı Exti 4
O Sr
5
Dollars = Penny//100
# Calculating the remaining pennies
6
Penny=Penny - (Dollars*100)
# Finding the number of Quarters
8
Quarter = Penny//25
10
# Finding the number of Quarters
11
Penny=Penny - (Quarter*25)
12
# Finding the number of Dime
13
Dime = Penny//10
14
# Finding the number of
Quarters
Penny=Penny - (Dime*10)
# Printing the Dollars, Quarter, Dime, Penny
15
16
17
if Penny <= 0:
What's wrong with this expression?
18
19
print('No change')
20
21
gif (Dollars):
if (Dollars>1):
print("Dollars:", Dollars)
22
23
24
else:
25
print("Dollar:", Dollars)
26
27
Gif (Quarter):
Run:
Enter pennies: -9
Dollar: -1
Quarters: 3
Dime: 1
Pennies: 6
Process finished with exit code 0
Transcribed Image Text:# Asking user input in pennies 1 > Penny = int(input("Enter pennies: ")) > 3 # Finding the number of Dollars > ullı Exti 4 O Sr 5 Dollars = Penny//100 # Calculating the remaining pennies 6 Penny=Penny - (Dollars*100) # Finding the number of Quarters 8 Quarter = Penny//25 10 # Finding the number of Quarters 11 Penny=Penny - (Quarter*25) 12 # Finding the number of Dime 13 Dime = Penny//10 14 # Finding the number of Quarters Penny=Penny - (Dime*10) # Printing the Dollars, Quarter, Dime, Penny 15 16 17 if Penny <= 0: What's wrong with this expression? 18 19 print('No change') 20 21 gif (Dollars): if (Dollars>1): print("Dollars:", Dollars) 22 23 24 else: 25 print("Dollar:", Dollars) 26 27 Gif (Quarter): Run: Enter pennies: -9 Dollar: -1 Quarters: 3 Dime: 1 Pennies: 6 Process finished with exit code 0
Expert Solution
Step 1

Instead of checking the value in penny after the calculation of other variables you need to check this variable just after the input. After checking for an inappropriate value the program should give some error message and exit itself. The below provided program will cover all these aspects.

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Program on Numbers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage