实际上有一个百万富翁举办的派对,我试图使用 2 位客人的结构数组来存储他们的姓名和年龄,然后最后我试图显示客人的总数并将他们除以他们的年龄组。帮帮我!这是我第一次发帖!请原谅我的错误!谢谢!
#include "iostream"
#include "string"
using namespace std;
struct guests
{
string name;
int age;
};
int main()
{
int i=0,j=0;
guests guest[1];
try
{
do{
cout<<"enter your name"<<endl;
getline(cin,guest[i].name).get();
cout<<"enter your age"<<endl;
cin>>guest[i].age;
cin.get();
i++;
}
while(i>0 && i<2);
cout<<i<<"number of guests attended the party"<<endl;
for(i=0;i<2;i++)
{
if((guest[i].age>19 && guest[i].age<31))
{
j++;
cout<<j<<"number of guests of age group between 20 and 30 are her"<<endl;
}
else if((guest[i].age>29 && guest[i].age<41))
{
j=0;
j++;
cout<<j<<"number of guests of age group between 30 and 40 are here"<<endl;
}
else
cout<<j<<"number of guests of agegroup between 40 and 50 are here"<<endl;
}
}
catch (int e)
{
cout << "An exception occurred. Exception Nr. " << e << endl;
}
return 0;
cin.get();
}