The faulty program below is supposed to print out every othe


The faulty program below is supposed to print out every other character of an entered word, starting with the first character. For example, the word \"education\" should become \"euain\". Correct the errors, referencing the line numbers at left. you do not need to rewrite the entire program include using namespace std; inc main(); cout

Solution

#include <iostream>

using namespace std;

int main()
{
cout<<\"Enter a word:\";
string s;
cin>>s; //cin<< should be changed to cin>>
int x=0; //initialize x
int y=s.length();
string z=\"\"; //initialize z
while(y>=x)
{
z=z+s.substr(x,1);
x=x+2; // x++ will print all the letters so, make it x+2
}
cout<<\"The string with every other letter is:\"<<z<<endl;
}

 The faulty program below is supposed to print out every other character of an entered word, starting with the first character. For example, the word \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site