Hello ladies and gents,
I'm trying to write this little program in wich I have to enter by keyboard a certain amount of numbers (int) not floating points, and the program must count how many different numbers I have entered, when the amount is equal to ten, it must say that the amount of different numbers has reached it's limit!
If the limit is not reached I must enter a word or letter like STOP or stop or s or whatever and the program should show me how many different numbers there actually are, wich of course is lower then 10.
I have written this piece of code, but it's not doing what it should do :)
int main()
{
int x, y=0, z=0, MAX= 10;
for (int i=0;y<MAX;i++)
{
if (y==MAX)
cout<< "The amount of different numbers has reached its limit!"<<endl;
else
{
cin>>x;
for (int i=0; i<MAX; i++)
if (x!=z)
{
y++;
z=x;
}
}
}
cout<< "The amount of different numbers is: " << y <<endl;
I also tried it out with an array because I was not and still am not certain wether this could be done without an array!
I think the control should be done by going threw the array each time a number is entered and that this should determine wether the number allready exists or not, if it exists, the amount should be added by 1, if not, I should be able to continue adding numbers until I decide to STOP!
const int amount=10;
int s[amount], x=0,y=0, z=0;
for (int i=0;i<10; i++)
{
cin>>s[i];
++y;
for (int i=0;i<y;i++)
{
if (s[i]!=s[i-1])
x++;
if(x==10)break;
cout<<"The amount of different numbers has reached its limit!";
}
}
cout<<"The amount of different numbers is: "<< x <<endl;
cout<<endl;
return 0;
}
Can someone please help me with this, thank you