So I'm working on a very basic text adventure game. I know that if else pyramids are frowned upon in programmes, though that isn't the issue here. I am looking for either a way to resolve the problem or a different way to go at the solution. So if the current method can't be fixed or it's easier to go at it a different way I'm open to either solution. Though I would prefer an explanation of why the solution works whatever it is. This is in C++
Enough intro on to the code and the error log.
Code:
#include <iostream>
#include <stdlib.h>
#include <string>
int main(){
std::string command;
while( 1 == 1 ){
std::cout << "Input Command" << std::endl;
getline(std::cin, command);
if( command == "exit"){
std::cout << "Exit command accepted" << std::endl;
}
else{
if(command == "; DROP TABLE students;"){
std::cout << "Haha, very funny" << std::endl;
}
}
else{
if(command == "Ascend"){
std::cout << "You have Ascended to godhood" << std::endl;
std::cout << "Victory is your's"
std::cout << "Just type 'cow' to end the game" << std::endl;
getline(std::cin, command)
if(command == "cow"){
exit(0);
}
else{
std::cout << "Bad Player Bad" << std::endl;
}
}
else{
std::cout << "Command not recognized" << std::endl;
}
}
return 0;
}
Logs
Code:
Source.cpp: In function ‘int main()’:
Source.cpp:17:3: error: ‘else’ without a previous ‘if’
else{
^
Source.cpp:21:4: error: expected ‘;’ before ‘std’
std::cout << "Just type 'cow' to end the game" << std::endl;
^
Source.cpp:23:4: error: expected ‘;’ before ‘if’
if(command == "cow"){
^
Source.cpp:26:4: error: expected ‘}’ before ‘else’
else{
^
Source.cpp:30:3: error: ‘else’ without a previous ‘if’
else{
^
Details, I am on lubuntu using g++ from the repositories.
Any help would be appreciated.
--Djyou