Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Need help with this problem. Code in C++ IV. Programming Assignment - Practice using cin and cout. - Practice using variables - Practice with loops
Need help with this problem. Code in C++
IV. Programming Assignment - Practice using cin and cout. - Practice using variables - Practice with loops and validation For this lab, you are going to create the code named lab1.cpp that asks the user for their dog's name (storing it as a string) and the dog's age (as an integer). The user can then do one of three things: play fetch, feed, or pet the dog. The most important thing is that if the user enters invalid values for the age (between 0 and 25) or the menu, it will prompt the user again. After any three choices, the program should exit. There are no starting files for this lab. You can see the sample output here (your output should match plus check for valid input): What is your dog's name? Tator Tot What is your dog's age? 2 What would you like to do? 1. Play fetch with Tator Tot 2. Feed Tator Tot 3. Pet Tator Tot 1 Tator Tot gets the stick and returns to you! What would you like to do? 1. Play fetch with Tator Tot 2. Feed Tator Tot 3. Pet Tator Tot 2 Tator Tot hungrily eats their food. What would you like to do? 1. Play fetch with Tator Tot 2. Feed Tator Tot 3. Pet Tator Tot 3 You happily pet Tator Tot. You are a great pet owner! Good-bye Please note: A "while loop" or "do while loop" is the best method to use to check the validity of input. You can always look up while and do...while loops online if you don't have the book. An issue that can arise with just declaring a variable is what old data may exist in that memory space. After we declare a variable, we set its initial value (called initialization). This is to ensure that the data in that memory location is valid. So, for this, we may want to initialize a variable to 0 as in: int myInt =0; If you have problems with this, please hop on Discord and ask the TA/TFs questionsStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started