Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In c++ #include using namespace std; int main() { char in_str[100];// string 1D

ID: 3836802 • Letter: I

Question

In c++

#include using namespace std;

int main() { char in_str[100];//

string 1D array of size 100

int count_e = 0; c

out << "Enter a string: ";

cin >> in_str; int i = 0; while(true)//infinite loop { if(in_str[i] == 'e') //

if an 'e' found then count it { count_e = count_e + 1; } i = i + 1; //check next index after each repetition

if(i == 100) // if all indexes are checked then escape the loop { break; } }

if(count_e == 0)//if no e found then say bye~

cout<<" There is no. bye~" << endl;

else

cout << endl << " there are " << count_e << endl;

return 0;

}

in this code How to code

if string has 'e' then this roop continue rotate

But don't found 'e ' escape this code

Explanation / Answer

Ans: i have provided the full working codes for the above problem. checked in Codeblocks.

#include<iostream>

using namespace std;

int main()

{

char in_str[100]; //declaring a 1D char array

int count_e=0,i=0;

cout<<"Enter a string: "; //taking input for array(i.e required string)

cin>>in_str;

while(i!=100)// it will find out no. of 'e' in a string check upto 100 indexes

{

if(in_str[i]=='e')

{

count_e=count_e+1; //count_e keep track of no. of 'e's

}

i++;

if(i==100)

{

break;

}

}

if(count_e==0)// i.e no 'e' present in the string

{

cout<<"There is no 'e' in the string..bye!!";

}

else

cout<<"Total number of 'e' in the string is/are: "<<count_e;

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote