how to define

the question was
Read one by one the characters of a sequence of characters ended by a point ". , And display the number of
'A' which contains.

I am not sure why this code isnt working
should i define the point in this case or what?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
  int main() {
	//variable declaration
	char A,S,nb;
	//ask user
	while (S!='.')
	{
	cin>>S;
	if (S='A')
	{nb=nb+1;
    }
    }
    cout<<"nb of A is"<<nb;
	return 0;
}


Last edited on
On line 8 you set the value of S to 'A'.

Perhaps you meant this:
if (S=='A')

What's the char A for on line 3? It doesn't get used. Remove it.

Is nb meant to be a number? If it is, you should make it a number type, like 'int'.

What value does nb begin with? What value did you want it to begin with? Better set it to that value at the start.
Last edited on
Line 3. A is unused. S is not initialised, it contains garbage - what if it already contains '.'?
nb should be an integer, not a char. nb is not initialised, it contains garbage.
line 8 if (S='A' to test if the values are equal, use ==, not =.
thx very much
it worked
Topic archived. No new replies allowed.