I am still new to programming with C++ and I'm trying out some If/Then statements. Basically I'm trying to do something where someone enters one of the spells from the different char and output different messages depending on the spell type you enter. For some reason though, I'm still missing something. Any input would be appreciated.
#include <iostream>
#include <iomanip>
#include <string>
usingnamespace std;
int main()
{
string input;
cout << "\nCast a spell: ";
cin >> input;
if input == "fire"
{
cout << "\nYou burned your enemy!!!: " << endl;
}
elseif input == "ice" //this is just style, else can be on its own line or with the next one. there is no 'elseif' single statement
{
cout << "\nYou froze your enemy!!!: " << endl;//freezed is not correct english.
}
//...etc
else cout <<"unknown attack, valid attacks are fire, ice, ... rock\n"return 0;
}
C:\WINDOWS\system32\cmd.exe /C ""C:/Program Files/mingw-w64/mingw64/bin/mingw32-make.exe" -j4 SHELL=cmd.exe -e -f Makefile"
"----------Building project:[ IFSTATE - Debug ]----------"
mingw32-make.exe[1]: Entering directory 'C:/CPP/IFSTATE/IFSTATE'
"C:/Program Files/mingw-w64/mingw64/bin/g++.exe" -c "C:/CPP/IFSTATE/IFSTATE/main.cpp" -g -O0 -std=c++17 -Wall -o Debug/main.cpp.o -I. -I.
C:/CPP/IFSTATE/IFSTATE/main.cpp: In function 'int main()':
C:/CPP/IFSTATE/IFSTATE/main.cpp:13:14: error: could not convert 'input' from 'std::__cxx11::string' {aka 'std::__cxx11::basic_string<char>'} to 'bool'
if (input) == "fire"
^
C:/CPP/IFSTATE/IFSTATE/main.cpp:13:16: error: expected primary-expression before '==' token
if (input) == "fire"
^~
C:/CPP/IFSTATE/IFSTATE/main.cpp:17:19: error: could not convert 'input' from 'std::__cxx11::string' {aka 'std::__cxx11::basic_string<char>'} to 'bool'
else if (input) == "ice" //this is just style, else can be on its own line or with the next one. there is no 'elseif' single statement
^
C:/CPP/IFSTATE/IFSTATE/main.cpp:17:21: error: expected primary-expression before '==' token
else if (input) == "ice" //this is just style, else can be on its own line or with the next one. there is no 'elseif' single statement
^~
C:/CPP/IFSTATE/IFSTATE/main.cpp:22:71: error: expected ';' before 'return'
else cout <<"unknown attack, valid attacks are fire, ice, ... rock\n"
^
;
C:/CPP/IFSTATE/IFSTATE/main.cpp:24:5:
return 0;
~~~~~~
mingw32-make.exe[1]: *** [IFSTATE.mk:98: Debug/main.cpp.o] Error 1
mingw32-make.exe: *** [Makefile:5: All] Error 2
mingw32-make.exe[1]: Leaving directory 'C:/CPP/IFSTATE/IFSTATE'
====6 errors, 0 warnings====
it was not meant to run. I clearly left off () on the if statement, have ... and etc all through it..
its how to do it, not done for you -- consider it pseudo code that is much like c++. I missed some ;s as well.
if statements require ():
if(input == "fire") is correct, if you did not know that.
if input == "fire" is not correct.
Give it a try with these ideas but your own code. If you can't get it, I will help explain whatever didn't work if you post your try.