Im making a program tha needs to type series of numbers until i enter any negative number or exeed 100 the loop stops and counts and displays the number of times i typed a specific number and displays the most number of times i entered the specific number (I am not allowed to use array, just loops and if..else)
Heres a code but was unfinished because my teacher said if i typed it one by one it would be wrong cuz there is a shorter code for that. But i want to learn what is this shorter code is...
#include <iostream>
using namespace std;
main ()
{
int x=0,count0=0,count1=0,count2=0;
cout<<"Enter a series of numbers : ";
for (x; x>=0;)
{
cin>>x;
if (x==0)
{
count0++;
}
else if (x==1)
{
count1++;
}
else if (x==2)
{
count2++;
}
}
cout<<"Number\t"<<"Times"<<endl;
if (count0>0)
{
cout<<"0\t"<<count0<<endl;
}
if (count1>0)
{
cout<<"1\t"<<count1<<endl;
}
if (count2>0)
{
cout<<"2\t"<<count2<<endl;
}
Unless you first ask for the specific number, there is no way to do this without some form of array. (Sure, you could do all kinds of fancy tricks with the stack or something, but as you don't know what I mean I doubt it would be a correct answer.)
Perhaps you (or we) are misunderstanding something about your assignment?
Do you have the exact words to your assignment?
The problem is, you're not being clear about your problem.
We can't talk about what you're doing and stumble on your problem and provide help. You have to be clear about what it is you have seen that you don't understand. A comments like "This is why i am so confused" doesn't help anyone.