I'm getting an error in this section of code here. "expected ; before cout" In particular, on line 4 in this section of code, just didn't post my whole code here
1 2 3 4 5 6 7
else{
(!(input == "The Captain" || input =="the captain" || input == "The New Guy" || input == "the new guy")) //accounting for incorrect input of canidate
//to be voted on
cout << "Canidate does not exist. Please vote again!" << ": " << endl;
cin >> input;
}
What are you trying to achieve with line 2 of the posted snipped? Did you intend that to be the condition in an "else if" statement?
As you've written it, that line doesn't do anything; it's a statement on its own that simply evaluates to a boolean value, but does nothing with that value.
The reason for the syntax error is that, as a standalone statement, the compiler is expecting a semicolon at the end.
#include <iostream>
#include <ctime>
#include <cstdlib>
usingnamespace std;
int main()
{
int uniqueNumber;
srand( time(0)); // This will ensure a really randomized number by help of time.
uniqueNumber=rand()%50+4; // Randomizing the number between 4-50.
cout << "Shows a random number: " << uniqueNumber << endl;
string NameOfCanidate;
string input;
//voting process, two choices for the pirates
cout << "Please decide who you will be voting for, the captain or the new guy: " << endl;
cin >> input;
if(input == "The Captain" || input =="the captain" || input == "The New Guy" || input == "the new guy") // if loop for input of
//pirate vote for election
{
cin >> NameOfCanidate;
}
else{
(!(input == "The Captain" || input =="the captain" || input == "The New Guy" || input == "the new guy")) //accounting for incorrect input of canidate
//to be voted on
cout << "Canidate does not exist. Please vote again!" << ": " << endl;
cin >> input;
}
cout << "Below is a list of the 10 amendments that the two pirates will vote on \naccording to the ships constitution" << endl;
int amendments = 0;
cin >> amendments; // selecting the amendment
switch (amendments){ // for outputting the amendment(s) voted on, which will
// be passed on to a function in main to call
case 1: cout << "What does the fox say? Whatever WE tell it to"; //case 1-10 are the 10 amendments to be voted on
break;
case 2: cout << "From now on the annual Cinco De Mayo party will be held on March 8th ";
break;
case 3: cout << "Beginning this year, sharks shall have a week dedicated to us";
break;
case 4: cout << "Pirates are now allowed to talk about fight club";
break;
case 5: cout << "When in Rome, the Romans will do as WE do.";
break;
case 6: cout << "Our mothers will immediately get tattoos that say SON";
break;
case 7: cout << "From now on the President will take our birthdays off.";
break;
case 8: cout << "If we say something costs an arm and a leg, it does";
break;
case 9: cout << "Freemasons are ordered to learn OUR secret handshake.";
break;
case 10: cout << "If a tree falls in the forest and no one is around, it will make a sound only with our permission ";
break;
// default: cout << "This won't be used since a amendment will always be voted on, thus never be shown or checked I believe.. (Please correct me) ";
// break;
}
}
A new thread wasn't created, more explanation was needed which my fault for not being specific enough, hence me posting more code, in particular, to find my error more efficiently. Thus, it's not "repeating yourself day here in cplusplus.com...".
On line 28, I'm trying to account for invalid input, valid input being that on line 22. I feel like it's something simple but can't seem to figure it out. Yeah I believe that's what I intended to do, to account for invalid input.
The point was that I had to repeat myself, because you didn't answer my question first time around.
So is the idea line line 25 executes if (input == "The Captain" || input =="the captain" || input == "The New Guy" || input == "the new guy") is true, and lines 30 - 31 execute if it isn't? Because, if so, you don't need line 28 at all. The else statement on line 27 already implements that logic.
Well, what do you want it to do? If you want it to repeat until a certain condition is met then, yes, loops are what you use to repeatedly execute the same code.