so like i was bored and decided to make a little prog that would run any game you typed in
Spoiler!
Code:
#include <iostream>
using namespace std;
int main() { cout << "Hello!\n" << endl; cout<<"What would you like to play? (type cmds for a list of commands)" <<endl; cout<< "\n\n\n"; cout<< "What you wanna do? "; string game; cin>> game; if (game == "freecell" || "Freecell") { system("START FREECELL"); } if (game == "spider" || "Spider") { system("START SPIDER"); }
if (game== "pinball" || "Pinball") { system("START PINBALL"); } if (game == "cmds") { cout<< "List of games : " <<endl; cout<< "\n\n"; cout << "Spider Solitaire \n"; cout << "Freecell \n"; cout << "Pinball \n"; }
return 0; }
problem is, when i type in a game, it runs all the games instead of just the one i typed =/ anybody have an idea on how to fix?
yea, the || separates 2 checking conditions, so in your case first the program checks if game (the input) is the same as "freecell", but then it also compares "Freecell" with nothing, which would always be true.
To run the program smoother, use an "else" after each "if". Also, make sure your conditions aren't always true
[SD]happynoobing wrote:
Cruor wrote:
Code:
if (game == "freecell" || "Freecell")
Always evaluates to true. Same with the rest.
yea, the || separates 2 checking conditions, so in your case first the program checks if game (the input) is the same as "freecell", but then it also compares "Freecell" with nothing, which would always be true.
it should be:
Code:
if (game == "freecell" || game == "Freecell")
thx guys
Grimm-.- wrote:
hmm... How did you guys learn this stuff?... Proper lessons by a teacher or over the internet?
Users browsing this forum: No registered users and 20 guests
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum