Source code
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int N,Amount;
double s=0,c=0,r=0,total=0;
char Type;
cin>>N;
while(N>0)
{
cin>>Amount;
cin>>Type;
total += Amount;
if(Type=='C')
{
c +=Amount;
}
else if(Type=='S')
{
s += Amount;
}
else if(Type=='R')
{
r += Amount;
}
N--;
}
cout<<"Total: "<<total<<" cobaias"<<endl;
cout<<"Total de coelhos: "<<c<<endl;
cout<<"Total de ratos: "<<r<<endl;
cout<<"Total de sapos: "<<s<<endl;
cout<<"Percentual de coelhos: "<<fixed<<setprecision(2)<<(100.00/total)*c<<" %"<<endl;
cout<<"Percentual de ratos: "<<fixed<<setprecision(2)<<(100.00/total)*r<<" %"<<endl;
cout<<"Percentual de sapos: "<<fixed<<setprecision(2)<<(100.00/total)*s<<" %"<<endl;
return 0;
}
Add your comment