Prepare a structure to store information on cat info (name , age , type). Create an array structured variable named CatInfo to receive 2 inputs from user.
#include <iostream>
using namespace std;
struct Cat
{
 string name;
 int age;
 string type;
};
int main()
{
  struct Cat CatInfo[2];
  for (int i=0;i<2;i++){
    cout<<"\nEnter the name of cat "<<i+1<<":";
    cin>>CatInfo[i].name;
    cout<<"\nEnter the age of cat "<<i+1<<":";
    cin>>CatInfo[i].age;
    cout<<"\nEnter the type of cat "<<i+1<<":";
    cin>>CatInfo[i].type;
  }
  for (int i=0;i<2;i++){
    cout<<"\nName : "<<CatInfo[i].name;
    cout<<"\nAge : "<<CatInfo[i].age;
    cout<<"\nType : "<<CatInfo[i].type;
  }
  return 0;
}
Comments
Leave a comment