Problem: Feed Nibble Monster Till Full Write a program that generates a number in [0, 500] at the beginning -- this corresponds to how hungry the monster is -- and keeps asking the user to feed the monster until that number falls to zero. Each time the user feeds the monster a nibble, hunger decreases by the decimal value of the character (i.e. if the user feeds 'A' hunger decreases by 65). But when the user feeds the monster some character that isn't a nibble, the hunger increases by the decimal value of the character (since puking depletes energy). Use while loop. Sample runs: Notice the loop exits after one iteration, because hunger was very low and one nibble made the monster full: wer on DESKTOP ZIONDUL MINGWOT / C/ COUT SES/CSZU11/ Code $ java NibbleMonsterwithLoopTill Full Monster hungry :E HUNGER: 2 Feed monster nibble :o a yum! Monster full :). You may go. weron@DESKTOP-2T8KDUL MINGW64 /c/courses/cs2011/code Notice hunger increasing after non-nibble (pink highlight): Weron DESKTOP 21IONDOL MINOWOT / C/ COUT SES/CSZUII/ CODE INOWOT $ java NibbleMonsterwith LoopTill Full Monster hungry :E HUNGER: 384 Feed monster nibble :o b yum! HUNGER: 286 Feed monster nibble :0 EWANI

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 20PE
icon
Related questions
Question

Problem: Feed Nibble Monster Till Full

Write a program that generates a number in [0, 500] at the beginning -- this corresponds to how hungry the monster is -- and keeps asking the user to feed the monster until that number falls to zero.

 

Each time the user feeds the monster a nibble, hunger decreases by the decimal value of the character (i.e. if the user feeds 'A' hunger decreases by 65). But when the user feeds the monster some character that isn't a nibble, the hunger increases by the decimal value of the character (since puking depletes energy).

 

Use while loop.

 

Sample runs:

Notice the loop exits after one iteration, because hunger was very low and one nibble made the monster full:

Notice hunger increasing after non-nibble (pink highlight):

Notice that the program just keeps going when the user feeds the monster only non-nibbles. Do you think the program will keep running forever if the user never gives the monster nibbles?

Problem: Feed Nibble Monster Till Full
Write a program that generates a number in
[0, 500] at the beginning -- this corresponds
to how hungry the monster is -- and keeps
asking the user to feed the monster until that
number falls to zero.
Each time the user feeds the monster a
nibble, hunger decreases by the decimal value
of the character (i.e. if the user feeds 'A'
hunger decreases by 65). But when the user
feeds the monster some character that isn't a
nibble, the hunger increases by the decimal
value of the character (since puking depletes
energy).
Use while loop.
Sample runs:
Notice the loop exits after one iteration,
because hunger was very low and one nibble
made the monster full:
Wet Off DESKTOP ZIONDUL MINGWO4 /C/COUT SES/CSZU11/ Code
$ java NibbleMonsterwithLoopTill Full
Monster hungry :E
HUNGER: 2
Feed monster nibble :o a
yum!
Monster full :).
You may go.
weron@DESKTOP-218KDUL MINGW64/c/courses/CS2011/code
Notice hunger increasing after non-nibble
(pink highlight):
DESKTOT ZIONDUL MINOWO" 77 courCS/CZUII/COue
$ java NibbleMonsterwithLoopTill Full
Monster hungry :E
HUNGE R: 384
Feed monster nibble :o b
yum!
HUNGE R: 286
Feed monster nibble :o *
Ewww! :O=*
HUNGER: 328
Feed monster nibble :0 7
m04r f00d!
HUNGE R: 273
Feed monster nibble :o z
Ewww! :O=Z
HUNGER: 395
Feed monster nibble :o f
yum!
HUNGER: 293
Feed monster nibble :o e
yum!
HUNGE R: 192
Feed monster nibble :08
m04r food!
HUNGE R: 136
Feed monster nibble :0 B
YUM!
HUNGE R: 70
Feed monster nibble :o a
yum!
Monster full :).
You may go.
7]
wonen@DESKTOR 2TOKDUL MINGWGA Ic/counces /cc2011/code
Notice that the program just keeps going
when the user feeds the monster only non-
nibbles. Do you think the program will keep
running forever if the user never gives the
monster nibbles?
Weron DESKTOP ZIORDUL MINGWO4 /C/Courses/CSZU11/ Code
$ java NibbleMonsterwithLoopTill Full
Monster hungry :E
HUNGER: 89
Feed monster nibble :0
Ewww! :O=*
HUNGE R: 131
Feed monster nibble :o & +
Ewww! :O=&
HUNGER: 169
Feed monster nibble :o @
Ewww! :o=@
HUNGE R: 233
Feed monster nibble :o z 4
Ewww! :0=Z
HUNGER: 355
Feed monster nibble :0 x
Ewww! :0=X
HUNGE R: 475
Feed monster nibble :o y 4
Ewww! :o=y
HUNGE R: 596
Feed monster nibble :o)
Ewww! :0=)
HUNGE R: 637
Feed monster nibble :0 ^
Ewww! :O=A
HUNGE R: 731
Feed monster nibble :0 +
Ewww! :0=+
HUNGER: 774
Feed monster nibble :0 !
Ewww! :O=!
HUNGER: 807
Feed monster nibble :0
Ewww! :O=~
HUNGER: 933
Feed monster nibble :0
2
له
Transcribed Image Text:Problem: Feed Nibble Monster Till Full Write a program that generates a number in [0, 500] at the beginning -- this corresponds to how hungry the monster is -- and keeps asking the user to feed the monster until that number falls to zero. Each time the user feeds the monster a nibble, hunger decreases by the decimal value of the character (i.e. if the user feeds 'A' hunger decreases by 65). But when the user feeds the monster some character that isn't a nibble, the hunger increases by the decimal value of the character (since puking depletes energy). Use while loop. Sample runs: Notice the loop exits after one iteration, because hunger was very low and one nibble made the monster full: Wet Off DESKTOP ZIONDUL MINGWO4 /C/COUT SES/CSZU11/ Code $ java NibbleMonsterwithLoopTill Full Monster hungry :E HUNGER: 2 Feed monster nibble :o a yum! Monster full :). You may go. weron@DESKTOP-218KDUL MINGW64/c/courses/CS2011/code Notice hunger increasing after non-nibble (pink highlight): DESKTOT ZIONDUL MINOWO" 77 courCS/CZUII/COue $ java NibbleMonsterwithLoopTill Full Monster hungry :E HUNGE R: 384 Feed monster nibble :o b yum! HUNGE R: 286 Feed monster nibble :o * Ewww! :O=* HUNGER: 328 Feed monster nibble :0 7 m04r f00d! HUNGE R: 273 Feed monster nibble :o z Ewww! :O=Z HUNGER: 395 Feed monster nibble :o f yum! HUNGER: 293 Feed monster nibble :o e yum! HUNGE R: 192 Feed monster nibble :08 m04r food! HUNGE R: 136 Feed monster nibble :0 B YUM! HUNGE R: 70 Feed monster nibble :o a yum! Monster full :). You may go. 7] wonen@DESKTOR 2TOKDUL MINGWGA Ic/counces /cc2011/code Notice that the program just keeps going when the user feeds the monster only non- nibbles. Do you think the program will keep running forever if the user never gives the monster nibbles? Weron DESKTOP ZIORDUL MINGWO4 /C/Courses/CSZU11/ Code $ java NibbleMonsterwithLoopTill Full Monster hungry :E HUNGER: 89 Feed monster nibble :0 Ewww! :O=* HUNGE R: 131 Feed monster nibble :o & + Ewww! :O=& HUNGER: 169 Feed monster nibble :o @ Ewww! :o=@ HUNGE R: 233 Feed monster nibble :o z 4 Ewww! :0=Z HUNGER: 355 Feed monster nibble :0 x Ewww! :0=X HUNGE R: 475 Feed monster nibble :o y 4 Ewww! :o=y HUNGE R: 596 Feed monster nibble :o) Ewww! :0=) HUNGE R: 637 Feed monster nibble :0 ^ Ewww! :O=A HUNGE R: 731 Feed monster nibble :0 + Ewww! :0=+ HUNGER: 774 Feed monster nibble :0 ! Ewww! :O=! HUNGER: 807 Feed monster nibble :0 Ewww! :O=~ HUNGER: 933 Feed monster nibble :0 2 له
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Array
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
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
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage