Hi. I'm writing a code for class and it isn't working the way I would like it to. The program keeps spitting it out sentences that shouldn't be there at that time even if the user input doesn't agree with them. Any help would be much appreciated!
#include <iostream>
usingnamespace std;
int main ()
{
string movie, Starwars, Lordoftherings, side, imperials, rebellion, character;
cout << "What is your favourite movie? Enter either Starwars or Lordoftherings: \n";
cin >> movie;
if (movie == "Starwars") {
cout << "Are you allied with the imperials or part of the rebellion? Enter imperials or rebellion: \n";
cin >> side;
}
elseif (movie == "Lordoftherings") {
cout << "Who is your favourite character? Enter Sam or Frodo: \n";
cin >> character;
}
else (movie != "Starwars" || movie != "Lordoftherings"); {
cout << "You don't don't like either of them? Are you crazy? \n";
}
if (side == "imperials") {
cout << "The dark side welcomes you. \n";
}
elseif (side == "rebellion") {
cout << "May the force be with you. \n";
}
else (side != "imperials" || side != "rebellion"); {
cout << "You're a freelance? Good luck out there. \n";
}
if (character == "Sam") {
cout << "Potatoes, mash em, boil em, stick em in a stew. \n";
}
elseif (character == "Frodo") {
cout << "Long live the courageous hobbit who brought the ring to mordor! \n";
}
elseif (character != "Sam" || character != "Frodo"); {
cout << "You must like Gimli the most! Who doesn't like a fat old dwarf! \n";
}
return 0;
}
Thanks for the quick reply! I have re coded with your suggestions, however, once I come to the second input where I either must enter Sam or Frodo for LOTR or Rebels or Imperials for starwars, it reverts back to saying "You don't don't like either of them? Are you crazy?"
#include <iostream>
usingnamespace std;
int main ()
{
string movie, Starwars, Lordoftherings, side, imperials, rebellion, character;
cout << "What is your favourite movie? Enter either Starwars or Lordoftherings: \n";
cin >> movie;
if (movie == "Starwars") {
cout << "Are you allied with the imperials or part of the rebellion? Enter imperials or rebellion: \n";
cin >> side;
}
elseif (movie == "Lordoftherings") {
cout << "Who is your favourite character? Enter Sam or Frodo: \n";
cin >> character;
}
else (movie != "Starwars" || movie != "Lordoftherings"); {
cout << "You don't don't like either of them? Are you crazy? \n";
return 0;
}
if (side == "imperials") {
cout << "The dark side welcomes you. \n";
}
elseif (side == "rebellion") {
cout << "May the force be with you. \n";
}
else (side != "imperials" || side != "rebellion"); {
cout << "You're a freelance? Good luck out there. \n";
return 0;
}
if (character == "Sam") {
cout << "Potatoes, mash em, boil em, stick em in a stew. \n";
}
elseif (character == "Frodo") {
cout << "Long live the courageous hobbit who brought the ring to mordor! \n";
}
elseif (character != "Sam" || character != "Frodo"); {
cout << "You must like Gimli the most! Who doesn't like a fat old dwarf! \n";
return 0;
}
return 0;
}
Ok I've made the changes you've suggested and it gets me farther into the program before spitting out two clauses. But, once I input the second question it spits out the "you must like Gimli the most" clause. Here it is with the changes in case I've messed something up again.
#include <iostream>
usingnamespace std;
int main ()
{
string movie, Starwars, Lordoftherings, side, imperials, rebellion, character;
cout << "What is your favourite movie? Enter either Starwars or Lordoftherings: \n";
cin >> movie;
if (movie == "Starwars") {
cout << "Are you allied with the imperials or part of the rebellion? Enter imperials or rebellion: \n";
cin >> side;
}
elseif (movie == "Lordoftherings") {
cout << "Who is your favourite character? Enter Sam or Frodo: \n";
cin >> character;
}
else {(movie != "Starwars" || movie != "Lordoftherings");
cout << "You don't don't like either of them? Are you crazy? \n";
return 0;
}
if (side == "imperials") {
cout << "The dark side welcomes you. \n";
}
elseif (side == "rebellion") {
cout << "May the force be with you. \n";
}
else {(side != "imperials" || side != "rebellion");
cout << "You're a freelance? Good luck out there. \n";
return 0;
}
if (character == "Sam") {
cout << "Potatoes, mash em, boil em, stick em in a stew. \n";
}
elseif (character == "Frodo") {
cout << "Long live the courageous hobbit who brought the ring to mordor! \n";
}
else {
(character != "Sam" || character != "Frodo");
cout << "You must like Gimli the most! Who doesn't like a fat old dwarf! \n";
return 0;
}
}
if (character == "Sam") {
cout << "Potatoes, mash em, boil em, stick em in a stew. \n";
}
elseif (character == "Frodo") {
cout << "Long live the courageous hobbit who brought the ring to mordor! \n";
}
else {
(character != "Sam" || character != "Frodo");
cout << "You must like Gimli the most! Who doesn't like a fat old dwarf! \n";
return 0;
}
Should be :
1 2 3 4 5 6 7 8 9 10 11
if (character == "Sam") {
cout << "Potatoes, mash em, boil em, stick em in a stew. \n";
}
elseif (character == "Frodo") {
cout << "Long live the courageous hobbit who brought the ring to mordor! \n";
}
elseif (character.size() > 0){
(character != "Sam" || character != "Frodo");
cout << "You must like Gimli the most! Who doesn't like a fat old dwarf! \n";
return 0;
}
Alright, so with this input, the whole Starwars section works as intended. The only problem left that I face is that when I input my favourite character for lord of the rings it spits out "You're a freelance? Good luck out there."
if (side == "imperials") {
cout << "The dark side welcomes you. \n";
}
elseif (side == "rebellion") {
cout << "May the force be with you. \n";
}
else {(side != "imperials" || side != "rebellion");
cout << "You're a freelance? Good luck out there. \n";
return 0;
}
Should be :
1 2 3 4 5 6 7 8 9 10
if (side == "imperials") {
cout << "The dark side welcomes you. \n";
}
elseif (side == "rebellion") {
cout << "May the force be with you. \n";
}
elseif (side.size() > 0){(side != "imperials" || side != "rebellion");
cout << "You're a freelance? Good luck out there. \n";
return 0;
}
#include <iostream>
usingnamespace std;
int main ()
{
string movie, Starwars, Lordoftherings, side, imperials, rebellion, character;
cout << "What is your favourite movie? Enter either Starwars or Lordoftherings: \n";
cin >> movie;
if (movie == "Starwars")
{
cout << "Are you allied with the imperials or part of the rebellion? Enter imperials or rebellion: \n";
cin >> side;
if (side == "imperials") {
cout << "The dark side welcomes you. \n";
}
elseif (side == "rebellion") {
cout << "May the force be with you. \n";
}
else (side != "imperials" || side != "rebellion"); {
cout << "You're a freelance? Good luck out there. \n";
}
}
elseif (movie == "Lordoftherings")
{
cout << "Who is your favourite character? Enter Sam or Frodo: \n";
cin >> character;
if (character == "Sam") {
cout << "Potatoes, mash em, boil em, stick em in a stew. \n";
}
elseif (character == "Frodo") {
cout << "Long live the courageous hobbit who brought the ring to mordor! \n";
}
elseif (character != "Sam" || character != "Frodo"); {
cout << "You must like Gimli the most! Who doesn't like a fat old dwarf! \n";
}
}
else
{
cout << "You don't like either of them? Are you crazy? \n";
}
return 0;
}
#include <iostream>
usingnamespace std;
int main ()
{
string movie, Starwars, Lordoftherings, side, imperials, rebellion, character;
cout << "What is your favourite movie? Enter either Starwars or Lordoftherings: \n";
cin >> movie;
if (movie == "Starwars")
{
cout << "Are you allied with the imperials or part of the rebellion? Enter imperials or rebellion: \n";
cin >> side;
}
elseif (movie == "Lordoftherings")
{
cout << "Who is your favourite character? Enter Sam or Frodo: \n";
cin >> character;
}
else {
(movie != "Starwars" || movie != "Lordoftherings");
cout << "You don't don't like either of them? Are you crazy? \n";
return 0;
}
if (side == "imperials") {
cout << "The dark side welcomes you. \n";
}
elseif (side == "rebellion") {
cout << "May the force be with you. \n";
}
elseif (side.size() > 0){(side != "imperials" || side != "rebellion");
cout << "You're a freelance? Good luck out there. \n";
return 0;
}
if (character == "Sam") {
cout << "Potatoes, mash em, boil em, stick em in a stew. \n";
}
elseif (character == "Frodo") {
cout << "Long live the courageous hobbit who brought the ring to mordor! \n";
}
elseif (character.size() > 0)
{
(character != "Sam" || character != "Frodo");
cout << "You must like Gimli the most! Who doesn't like a fat old dwarf! \n";
return 0;
}
}