Hello guys, I'm trying to make a program where the user inputs a sequence of numbers I.E 1 0 0 3 4 0 6 0 0 (numbers separated by spaces) and the program has to tell them the majority number, in this case '0'. I have compiled a program, however it only accounts for single digits. In example, if the user inputs, 800, 500, 800, 800, the program will tell them that the majority number is '0', however in reality, it is 800 (since it is separated by spaces from the other numbers). I have no idea on how to approach fixing it. Here's my code.
string input;
int numof0=0;
int numof1=0;
int numof2=0;
int numof3=0;
int numof4=0;
int numof5=0;
int numof6=0;
int numof7=0;
int numof8=0;
int numof9=0;
cout<<"Enter sequence of numbers (separated by spaces)"<<endl;
getline(cin,input);
for(unsignedint i=0;i<input.length();i++)
{
if(input.at(i)=='0')
{
numof0++;
}
if(input.at(i)=='1')
{
numof1++;
}
if(input.at(i)=='2')
{
numof2++;
}
if(input.at(i)=='3')
{
numof3++;
}
if(input.at(i)=='4')
{
numof4++;
}
if(input.at(i)=='5')
{
numof5++;
}
if(input.at(i)=='6')
{
numof6++;
}
if(input.at(i)=='7')
{
numof7++;
}
if(input.at(i)=='8')
{
numof8++;
}
if(input.at(i)=='9')
{
numof9++;
}
}
float total=numof0+numof1+numof2+numof3+numof4+numof5+numof6+numof7+numof8+numof9;
if(numof0/total>0.5)
{
cout<<"The majority value is '0'" <<endl;
}
if(numof1/total>0.5)
{
cout<<"The majority value is '1'" <<endl;
}
if(numof2/total>0.5)
{
cout<<"The majority value is '2'" <<endl;
}
if(numof3/total>0.5)
{
cout<<"The majority value is '3'"<<endl;
}
if(numof4/total>0.5)
{
cout<<"The majority value is '4'"<<endl;
}
if(numof5/total>0.5)
{
cout<<"The majority value is '5'"<<endl;
}
if(numof6/total>0.5)
{
cout<<"The majority value is '6'"<<endl;
}
if(numof7/total>0.5)
{
cout<<"The majority value is '7'"<<endl;
}
if(numof8/total>0.5)
{
cout<<"The majority value is '8'"<<endl;
}
if(numof9/total>0.5)
{
cout<<"The majority value is '9'"<<endl;
}