Nov 7, 2017 at 2:50pm UTC
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 Nov 7, 2017 at 2:55pm UTC
Nov 7, 2017 at 3:05pm UTC
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 Nov 7, 2017 at 3:06pm UTC
Nov 7, 2017 at 3:12pm UTC
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 =
.