Using array only

Develop a c++ program that asks a user to enter a c
haracter and a sentence then displays the
location of that character present in that sente
nce (Assume space as a character).if character
is not present also report that .
For example:
Please enter the sentence:
I love Pakistan.
Please enter the character you want to search: a
Output:
---------------------------------------------------
-
The character

a”
is present on location(s)
9 , 14
This is my code below please tell me how to correct my mistake

#include <iostream>
using namespace std;
main()
{char a[50];
char b;
cout<<"Enter Sentence: ";
cin>>a[50];
cout<<"Enter character: ";
cin>>b;
for(i=0;i<b;i++)
if(a==b)
cout<<i}
please use code tags.
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
using namespace std;
main()
{char a[50];
char b;
cout<<"Enter Sentence: ";
cin>>a[50];
cout<<"Enter character: ";
cin>>b;
for(i=0;i<b;i++)
if(a==b)
cout<<i}
1
2
3
4
5
for(int i = 0; i < 50; i++)
{
    if(a[i] == b)
        cout<<i<<" ";
}
Topic archived. No new replies allowed.