When I try to run the program it gives me an erron saying Expected expresion on
ID: 670762 • 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;
}
Explanation / Answer
Hi
There are lots of Syntax error in your code
And if you look carefully about your problem, You are getting that error because you have open unwanted parenthesis and did not close it.
Look at
if (sub.length()!=3){ // look in this line you open one bracket
{ // Here also you open one bracket
cout << "Incorrect length of substring" << endl;
} // But here you close only one bracket.
else if(phrase.find(sub_String)!=std::string::npos)
This is the reason you are getting this error.
Please Note: Inspite of this you code also contains many others error like you have used many such functions which are not present in header files. But you did not ask about these So I am not mentioning those other errors. If you want you can repost the question with required mention problems. Thanks :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.