1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
kramer
4 years ago
5

Need help with this C++ question

Computers and Technology
1 answer:
sertanlavr [38]4 years ago
4 0

Answer:

Here is the improvement of the program:

#include<iostream>  //to use input output functions

using namespace std;// to identify objects like cin cout

int main()  {   //start of main function

  string pet;         // "cat" or "dog"  

  char spayed;       // 'y' or 'n'      

  // Get pet type and spaying information  

cout << "Enter the pet type (cat or dog): ";   //prompts user to enter pet type

  cin  >> pet;   //reads input pet type

  if(pet=="cat"|| pet=="dog")     {   //use OR operator to check the type

  cout << "Has the pet been spayed or neutered (y/n)? ";   //prompts user to input if pet been spayed or neutered

  cin  >> spayed;}   //reads input spayed value

  else   // display the message below

  cout<<"only cats and dogs need pet tags";        

  // Determine the pet tag fee  

if (pet == "cat")   //if type of pet is cat

  {  if (spayed == 'y' || spayed == 'Y')  //lowercase or upper case y is accepted  

        cout << "Fee is $4.00 \n";   //if spayed is y or Y

     else   //if spayed is not y or Y

        cout << "Fee is $8.00 \n";   }  

  else if (pet == "dog")   //if type is dog

  {  if (spayed == 'y' || spayed=='Y')   //if spayed is y or Y

        cout << "Fee is $6.00 \n";  

     else   //if spayed is not y or Y

        cout << "Fee is $12.00 \n";    }        

  return 0;   }

 

Explanation:

Step 1:

Here is the copy of original source code:

#include <iostream>

using namespace std;

int main() {

string pet;

char spayed;

cout <<"Enter the pet type (cat or dog): ";

cin >> pet;

cout <<"Has the pet been spayed or neutered (y/n)?" ;

cin >>spayed;

if (pet=="cat") {

if (spayed=='y')

cout<< "Fee is $4.00 \n";

else

cout<< "Fee is $8.00 \n"; }

else if (pet== "dog") {

if (spayed=='y')

cout<<"Fee is $6.00 \n";

else

cout<<"Fee is $12.00 \n";}

else  

cout<<"Only cats and dogs need pet tags";

return 0; }

Step 2:

Compile the program and then run it 7 times

Run       Input Data         Fee Information                                      Correct

 1                cat y               Fee is $4.00                                           Yes  

 2               cat n               Fee is $8.00                                           Yes    

 3               cat Y               Fee is $8.00                                           No

 4               dog y              Fee is $6.00                                           Yes

 5               dog n              Fee is $12.00                                         Yes

 6               dog Y              Fee is $12.00                                         No

 7              hamster n        Only cats and dogs need pet tags       Yes                

Step 3:            

See the Answer section

OR logical operator is used so that either a lowercase 'y' or an uppercase 'Y is accepted:

if (spayed == 'y' || spayed == 'Y')

program only execute the spay/neuter prompt and input when the pet type is cat or dog:

if(pet=="cat"|| pet=="dog")  

 {     cout << "Has the pet been spayed or neutered (y/n)? ";    

cin  >> spayed; }    

else    

cout<<"only cats and dogs need pet tags";      

Step 4:

Run       Input Data         Fee Information                                      Correct

 1                cat y               Fee is $4.00                                           Yes  

 2               cat n               Fee is $8.00                                           Yes    

 3               cat Y               Fee is $4.00                                           Yes

 4               dog y              Fee is $6.00                                           Yes

 5               dog n              Fee is $12.00                                         Yes

 6               dog Y              Fee is $6.00                                           Yes

 7              hamster         Only cats and dogs need pet tags          Yes  

In the last input hamster the program does not ask for spayed information. It only asks to Enter the pet type. When the user enters hamster the program displays the message: Only cats and dogs need pet tags.

You might be interested in
IVD. IIIcelTICISTUSTUSE LIICIULUI 1.12. Which of the two systems do you think will need the largest motor? Explain your answer.​
zhannawk [14.2K]
Transmission motor motor
8 0
3 years ago
To find the ____, the net present value of the system is calculated by combining the net present value of the costs of the syste
Diano4ka-milaya [45]

Answer: c) Return on investment (ROI)

Explanation:

Return on investment (ROI)  is defined as term that measures the performance of single investment efficiency or numerous investment plans. It evaluates and assess plan of investment in form of ratio or percentage.

  • Return of investment(ROI) plan is calculated through dividing the return of investment by investment cost.
  • Other options are incorrect because cash return on capital invested ,carried forward(CF) and BI (business intelligence) are not used for calculating the investment plan through cost and benefit.Thus, the correct option is option(c)
8 0
3 years ago
What can you search on Microsoft Word or Powerpoint Clipart or Google (Clip art) to find more pictures like the ones below but w
elena-14-01-66 [18.8K]
Well if you put sad/mad/scared/tired/ect it should pop up with the same person.
3 0
3 years ago
Simple measurement questions, I'm on #5 right now but if you know any other ones that would be helpful (picture)
dangina [55]

Answer:

one inch=25.4

12 meters=13.12

10 quarts=9.46

12 milliliters=0.0004

400 pounds= 181 kg

25 meters/second=82

68F=20C

Explanation:

heres the full ones

one inch=25.4

12 meters=13.1234 yards

10 quarts=9.46353

12 milliliters=0.000405768

400 pounds=181.437

25m/s=82.021f/s

68f=20C

7 0
3 years ago
Uses of internet write in point.​
Vladimir [108]

Answer:

-Electronic mail. At least 85% of the inhabitants of cyberspace send and receive e-mail. ...

-Research.

-Downloading files.

-Discussion groups. ...

-Interactive games. ...

-Education and self-improvement. ...

-Friendship and dating. ...

-Electronic newspapers and magazines.

3 0
3 years ago
Other questions:
  • The Caesar Cipher has 25 different shifts to try.
    14·1 answer
  • In fiberoptic cable, the signal source is__________waves
    7·1 answer
  • The first computer introduced was the IBM PC. A. True B. False
    11·2 answers
  • The count function is used to total the values stored in numeric columns.
    8·1 answer
  • Write a java program which uses methods for calculating the sum of any 5 non-zero integer digits that are input. The program mus
    8·1 answer
  • If a website ends with .gov does it mean that its written by the government or?
    11·2 answers
  • PLEASE HELP QUICK WILL GIVE BRAINLY
    6·1 answer
  • How do I turn on your asus chromebook flip?
    12·1 answer
  • 3.
    5·1 answer
  • List of bad websites and why
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!