little help pls


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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  #include<iostream>

using namespace 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.
Last edited on
Topic archived. No new replies allowed.