132k views
1 vote
Create an algorithm that will convert dog years to human years using the assumption that 1 dog year = 7 human years. Prompt the user to enter the dog’s age in years. Multiply the dog’s age by 7 to calculate the human age equivalent of the dog’s age. For example, if a dog’s age is 2, the calculation should be human age equivalent = 2 * 7, which evaluates to the human equivalent of 14 years old. Output the result to the screen. Write the algorithm using pseudocode, and create a desk check using at least one set of test data.

1 Answer

1 vote

Answer:

Algorithm:

1. Declare and initialize variable one_dog_year=7.

2.Ask user to give dog age.

2.1 Read the dog age and assign it to variable "dog_age".

3.Create a variable "human_age" to store the equivalent human age.

3.1 Calculate equivalent human age as "human_age=one_dog_year*dog_age".

4.Print the equivalent human age of dog age.

7. End the program.

// here is algorithm implemented in c++

#include <bits/stdc++.h>

using namespace std;

int main()

{

// initialize one dog year

int one_dog_year=7;

int dog_age;

int equi_h_age;

cout<<"Enter the dog age:";

// read the dog age

cin>>dog_age;

//calculate the equivalent human age

equi_h_age=dog_age*one_dog_year;

cout<<"equivalent human age is : "<<equi_h_age<<endl;

return 0;

}

Output:

Enter the dog age:2

equivalent human age is : 14

User Endy
by
7.7k points