76 817
Assignments Done
Successfully Done
In June 2019

Answer to Question #46611 in C++ for amanda shaffer

Question #46611
Write a program that prompts the user to enter string and them prompts the user to enter a character. The program should display the location of the first occurrence of the character d, the program should say that the character is character number 5 in the string. If the character does not occur in the string, the program should display an appropriate message.
Expert's answer
#include <iostream>
#include <string>
using namespace std;
int main()
string st;
char ch;
cout << "Enter your string : ";
int pos = -1;
cin >> st;
cout<<"Enter your character : ";
cin >> ch;
bool here = false;
for (int i = 0; i < 100; i++)
if (st[i] == ch)
pos = i;
if (pos == -1)
cout << "Character is not found";
cout << "character found on position " << pos + 1;
return 0;

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions