Need Help

I need help with this code. Thanks!

#include<iostream>
using namespace std;
int main()
{
double a{26}, x;
int i,n;
cout<<"Members:"; cin>>n;
for(i=0;i<n;i++ cin>>a{i};
cout<<"x=";
cin>>x;
i=0;
while((a{i}!=x)&&(i<n)) i++;
if({a}==x)
cout<<"No one";
else cout<<"We have a member with...";
return 0;


}
Hi
the problem is with a
is that a an arrey?
if yes you have to say a[26] not a{26}
when you use a{26} it means a=26....
so for arrey we should use []
then in your first loop you forgot to close the ()....
and for the if({a}==x) what that mean?
do you wanna check the a[i] with x?
Ok i edit it but i shows me more mistakes:
http://prntscr.com/lc4ix6
Last edited on
Hehehe sorry aggain ... my fault.
Everythings is right now!
Hello rosko,

PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code.

It makes it easier to read your code and also easier to respond to your post.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.


I found the second link to be the most help.

I am glad you figured out what was wrong.

Just as a tip with proper indenting and a few blank line it becomes clear what some of the problems are.

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
26
#include<iostream>
using namespace std;
int main()
{
	double a{ 26 }, x;
	int i, n;

	cout << "Members:"; cin >> n;

	for (i = 0; i < n; i++ cin >> a{ i };

	cout << "x=";
	cin >> x;

	i = 0;

	while ((a{ i } != x) && (i < n))
		i++;

	if ({ a } == x)
		cout << "No one";
	else
		cout << "We have a member with...";

	return 0;
}


The for loop on line 10 ending it with a semi-colon limits the for loop to just that line. If anything from line 10 to 23 is to be part of the for loop they are not because you need {}s for more than one line.

Lines 17 and 18, 18 what use to be the end of 17, without any {}s line 18 is the only part of the while loop.

I did change the indenting to emphasize what the compiler sees.

I am not sure what your intention was, but that is what I see.

Hope that helps,

Andy
Topic archived. No new replies allowed.