Parks Canada has asked you to write a program to keep track of various animal po
ID: 3814858 • Letter: P
Question
Parks Canada has asked you to write a program to keep track of various animal populations in Waterton Lakes National Park. The staff estimates that 1000 different types of animal live in the park. Write a program that prompts the user for the type and population of each animal in the park (for example, there are 100 grizzly bears). Your program must check (and correct, if necessary) to ensure that all population values are valid. Then, your program will calculate and display the following: 1) The total number of animals in the park, and 2) Each type of animal, its current population, and its percentage of the total animal population.Explanation / Answer
Code:-
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
struct zoo{
string type;
int num;
};
int main() {
zoo animal[5];
int tot=0;
for(int i =0;i<5;i++){
cout<<"Enter the type of animal";
cin>>animal[i].type;
cout<<"Enter the number of the type entered";
cin>>animal[i].num;
tot=tot+animal[i].num;
}
cout<<"The total number of animals : "<<tot<<endl;
for(int i=0;i<5;i++){
cout<<"the type of animal : "<<animal[i].type<<endl;
cout<<"the current population : "<<animal[i].num<<endl;
double percentage=((double)animal[i].num/(double)tot)*100;
cout<<"The percentage = "<<percentage<<"% "<<endl;
}
return 0;
}