473,395 Members | 1,422 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

I am getting an error by the bool function 'expected unqualified - id before '{' toke

#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

//---Do not edit the following
//StartProvided
const int ERROR_CONVERSION = 1;
/*
Preconditions: Parameter is positive
Output stream is not in an error state
Postconditions: Ouput stream contains the lucas sequence up to given number of terms
Output stream is not in an error state
*/
void genLucasSequence(int intTerms);

/*
Preconditions: Parameter is a non-empty string
Postconditions: Boolean value indicating validity is returned
*/
bool isValidBinaryString(string strNumber);

/*
Preconditions: Parameter 2 and 3 are variable (non-literal, non const) integers
Postconditions: Parameter 2 and 3 are modified to contain appropriate boolean values
*/
void isPositiveAndEven(int intValue, bool& blnPositive, bool& blnEven);

/*
Preconditions: Parameter is positive
Postconditions: Vector containing terms of sequence is returned
*/
vector<int> genCollatzSequence(int intValue);

/*
Preconditions: Output stream is not in an error state
Postconditions: Converted value is returned if valid or program is terminated
*/
int promptForNumber();

int main()
{
bool blnContinue = true; //Loop control variable
do
{
while(cin.fail()) //Purge stream if needed
{
cin.clear();
string strJunk = "";
getline(cin, strJunk);
}
cout << "a) Lucas Sequence" << endl
<< "b) Validate binary string" << endl
<< "c) Test for positive and even" << endl
<< "d) (Bonus) Generate Collatz sequence" << endl
<< "e) Quit" << endl
<< "Enter selection: ";
char chChoice = '\0'; //Capture menu option
cin >> chChoice;
//Actual parameters for functions
string strBinaryNumber = "";
int intValue = 0;
bool blnPositive = false;
bool blnEven = false;
//Variable to hold return values
vector<int> vecSequence;
switch(chChoice) //Menu selection
{
case 'a':
case 'A':
intValue = promptForNumber(); //Prompt user
genLucasSequence(intValue); //Generate sequence
break;
case 'b':
case 'B':
cout << "Enter binary string: ";
getline(cin, strBinaryNumber); //Prompt user
if(isValidBinaryString(strBinaryNumber)) //Output based on result
cout << endl << "Number is a binary string" <<endl;
else
cout << endl << "Number is not a binary string" << endl;
break;
case 'c':
case 'C':
intValue = promptForNumber();
isPositiveAndEven(intValue, blnPositive, blnEven); //Pass by reference
if(blnPositive) //Output based on result
cout << "Number is positive" <<endl;
else
cout << "Number is not positive" << endl;
if(blnEven)
cout << "Number is even" <<endl;
else
cout << "Number is odd" << endl;
break;
case 'd':
case 'D':
{
intValue = promptForNumber(); //Prompt user
vecSequence = genCollatzSequence(intValue); //Generate sequence
cout << "Collatz Sequence: ";
for(int k = 0; k < vecSequence.size(); k++)
cout << vecSequence[k] << endl;
}
break;
case 'e':
case 'E':
blnContinue = false; //Quit by ending main loop
break;
default: //Inform user of invalid option being selected
cerr << "Invalid option, try again" << endl;
}

} while(blnContinue); //End of menu loop
return 0;
}

//An example of a value returning function implementation
int promptForNumber()
{
int intValue = 0;
cout << "Enter number: ";
cin >> intValue;
if(cin.fail())
{
cerr << "Invalid conversion" << endl;
exit(ERROR_CONVERSION);
}
return intValue;
}

//EndProvided

//--Edit after this point.
//Your code for the function implementations goes here
void genLucasSequence(int intTerms)
{
int a = -1;
int b = 2;
intTerms = 0;
cout << "Enter the number of terms" << endl;
cin >> intTerms;

for (int i=1; i<=intTerms; i=i+1)
{
int c = a;
a = b;
b = c + b;
}
cout << b << endl;
}

bool isValidBinaryString(string strNumber);
{ // this is where my error is.
strNumber = " ";
{
if(strNumber = "0") | (strNumber = "1")
return (strNumber true)
else
return (strNumber false)
}
}


void isPositiveAndEven(int intValue, bool& blnPositive, bool& blnEven);
{
intValue = 0;
cout << "Enter a number" << endl;
cin >> intValue;

blnPositive = intValue > 0;
blnEven = intValue / 2;

}

vector<int> genCollatzSequence(int intValue);
{
vector<int>vecSequence
vecSequence.push_back(intValue);
while(intValue>1)
{
if (intValue%2==0);
intValue = intValue / 2
else
intValue = intValue*3+1;
vecSequence.push_back(intValue);
}
return vecSequence;
}

bool OptionE(bool blnContinue)
{
return (blnContinue false)
}
Mar 12 '15 #1
3 2764
donbock
2,426 Expert 2GB
Remove the semicolon from the line immediately above the comment "this is where my error is". The semicolon makes that line a function declaration (that is, a function prototype), but you want a function definition. This same mistake occurs at least twice more in subsequent lines .
Mar 12 '15 #2
i am getting the same error
Mar 12 '15 #3
donbock
2,426 Expert 2GB
There weren't any changes in the error message or associated line number?

Starting from your "this is where my error is" comment and focusing on syntax issues...
  1. Next line. I'm not familiar with C++ string type, but this line looks like what I would expect to be ok.
  2. Next line. This open brace is legal, but it doesn't do anything useful.
  3. Next line. Change each = into == then change | into || finally enclose entire condition in parentheses.
  4. Next line. I don't understand what (strNumber true) means, but even if that is ok, need to terminate this line with a semicolon.
  5. Next line. Ok
  6. Next line. I don't understand what (strNumber false) means, but even if that is ok, need to terminate this line with a semicolon.

By the way, it would be a lot easier to refer to specific lines in your program if you enclosed the entire block of code in [CODE/] tags.
Mar 17 '15 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Squid Seven | last post by:
This is just bizarre. for the following snippet of code: #include <string> using std::string; I get the error message:
3
by: Thomas Barth | last post by:
Hi, I was wondering if someone had any insight to what I am doing wrong. I ve got a class with two methods that call static methods of another class. When compiling my sourcecodes I get the error...
1
by: tazpit32 | last post by:
I am receiving in several of my programs an error that is returning an expected unqualified-id before. Has anyone ever seen this? I have been working on it for a couple of days trying to figure...
7
by: Warrax | last post by:
I am currently doing online tutorials for C++, and am pretty much stuck in a rut about this problem. It is saying that there's an expected unqualifed-id before '{' token (I will post the code in just...
2
by: fhasdkfhadlksfjhalsdkfh12 | last post by:
I've been working on a decryption program for another encryption program I made. It isn't finished, and when I try to compile it to test it, it gives me the error "expected unqualified-id before...
9
by: erictheone | last post by:
Ok so what I'm trying to do is create a trans location cipher. For those among us that don't know alot about cryptography it is a method for jumbling up letters to disguise linguistic...
12
by: sam23 | last post by:
Hi all, im new to this programming language and i tried to use my Xcode to build and run this code but i got a error :(, and another error is i need a help guys #include <GLUT/glut.h>...
3
by: Elohim | last post by:
Hi to everybody, I'm a learner of C++. I'll really appreciate if you can help me or teach me something. Thank you in advance. #include<iostream> #include<string> int main() { ...
1
by: dragon1247 | last post by:
i have a game code i got online and am trying to execute in C++ but i keep getting the unqualified id error and can't figure out what it means here's my code { <div id="game"><embed...
3
by: darshan123 | last post by:
#include<stdio.h> #include<conio.h> #include<math.h> void main() { int i=1,j=2; float k,l=1.5; printf("%d %d\n",i,j);
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.