Hi i just need some help with this code
The program must accept 7 values or stop it when you type s.
The code not only couts the element, but also some other random numbers.
Any help would be appreciated, thanks.
#include<iostream>
usingnamespace std;
int main()
{
int numb[7];
int i;
char s;
for (i=0;i<=6;i++)
{
cout << "Please enter number:";
cin >> numb[i];
while (i=='s');
}
for (i=0;i<=6;i++){
cout <<endl<<numb[i]<<endl;
}
system("pause");
return 0;
}
it's because regardless of when the user types 's' you still output your whole array.
You could keep a count of the the elements populated then use this number in your for condition on line 17.
OR initialise your whole array with zero's (always a good idea to initialise stuff), then only output until you hit a zero in the array. when this happens you could use break to exit the for loop.