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

When I try to run the program it gives me an erron saying Expected expresion on

ID: 670764 • Letter: W

Question

When I try to run the program it gives me an erron saying Expected expresion on this line,

else if(phrase.find(sub_String)!=std::string::npos).

#include

#include

#include

using namespace std;

  

int main( )

{

  

  

  

// Defining variables.

//Initilizing variables.

int magicNum;

int magicNum1;

int position;

int phraseLenght;

string vowels = "aeiou";

string phrase;

string sub;

  

   // The phrase and the sub phrase

cout << "Enter a phrase:" << endl;

std::getline (std::cin,phrase);

  

cout << "Enter a 3-character sub:" << endl;

cin >> sub;

  

if (sub.length()!=3){

  

{

cout << "Incorrect length of substring" << endl;

  

  

}

else if(phrase.find(sub_String)!=std::string::npos){

  

cout << "Substring occurs " << phase.find(sub) << endl;

  

position = phrase.find(sub)

  

// removes the substring.

  

cout << "Phrase without substring is:" << phrase.replacement(position,3,"") << endl;

  

//finding length of magic string

  

phraselength = phrase.lenght();

  

magicNum = phrase.Length % 5;

  

magicNum1 = phrase.find_first_of(vowels);

  

if (magicNum == 0)

}

if (magicNum1 = 5)

{

  

cout<<"magic string!"<< endl;

}

  

}

else

{

cout<<"Not a magic string";

  

}

return 0;

}

Comment

Explanation / Answer

#include<iostream>
#include<string>
using namespace std;
  
int main( )
{
  
  
  
// Defining variables.
//Initilizing variables.
int magicNum;
int magicNum1;
int position;
int phraselength;
string vowels = "aeiou";
string phrase;
string sub;
  
// The phrase and the sub phrase
cout << "Enter a phrase:" << endl;
std::getline (std::cin,phrase);
  
cout << "Enter a 3-character sub:" << endl;
cin >> sub;
  
if (sub.length()!=3)
  
{
cout << "Incorrect length of substring" << endl;
  
  
}
else if(phrase.find(sub)!=std::string::npos){
  
cout << "Substring occurs " << phrase.find(sub) << endl;
  
position = phrase.find(sub);
  
// removes the substring.
  
cout << "Phrase without substring is:" << phrase.replace(position,3,"") << endl;
  
//finding length of magic string
  
phraselength = phrase.length();
  
magicNum = phrase.length() % 5;
  
magicNum1 = phrase.find_first_of(vowels);
  
if (magicNum == 0)
{
if (magicNum1 = 5)
{
  
cout<<"magic string!"<< endl;
}
  
}
else
{
cout<<"Not a magic string";
  
}
}
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