Click here to Skip to main content
13,049,343 members (73,110 online)
Rate this:
Please Sign up or sign in to vote.
See more:
#include <iostream>
int main(){
using namespace std;
int x;
string answer ;
cout<<"Welcome to Jumble!";
cout<< endl;
cout<<"We have over 1 words to unjumble!";
cout<< endl;
cout<<"Select a number. Each number represents a puzzle.";
cout<< endl; 
cout<<"After Selection, you will see a word. Type it in its unjumbled form.";
cout<< endl;
cout<< "Type a number!";
cout<< endl;
cin>> x;
if (x==1){
cout<< endl;
cout<< "Your word is: bthabtu";
cin>> answer;
	cout<< endl;
	cout<< "You are correct!";

I am new to C++. I decided to make a Jumble Word Game to improve my If Statement Skills. The line I crossed out has an error. Bathtub is not declared in this scope. I am sure this is a newbie mistake, but I wish to better myself. Any ideas what went wrong? Thanks, Brian.
Posted 24-Feb-14 13:38pm
SoMad 24-Feb-14 20:08pm
Look at the two lines right above that line. Do you see the difference in how the variable (answer) is written compared to the text?

Soren Madsen

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You did not declare some variable, bathtab anywhere at all and complain that it is not declared. So how about using some rational thinking? This is not even about being newbie or not.

Ideas? Hm… Well, think about it, if you did not declare something, will it appear declared in some mystical way?

And if you decide to create a game to improve your "if statement skills", probably your idea of the total volume of what you need to learn is highly distorted, otherwise you would try to move forward in bigger steps. I don't even know what to advise… probably: try to see the root cause of things.

Member 10622390 24-Feb-14 20:21pm
No need to be snide... but thanks I suppose. I literally just started programming an hour ago. Hello World, and such...
Sergey Alexandrovich Kryukov 24-Feb-14 20:42pm
Great. First of all, I would like to congratulate you with joining the party! You are very welcome. :-)

"Snide" is not a very nice expression in your welcome words when you are joined, especially to the one who really tried to help you. If you are just starting, my advice is the advice which really can help. If you are going to be so sensitive to criticism and some irony, it won't make your way easier; and it won't help you to gain respect. Respect is more usually earned by hard-working people with good deal of self-irony and humor...

Anyway, if you got it, please accept the answer formally (green "Accept" button). If not (or anyway), your follow-up questions will be welcome.

Member 10622390 24-Feb-14 20:51pm
Yeah, sorry about that. Figured it out. Changed string to YourAnswer. Made Cin>> YourAnswer. Then If YourAnswer="bathtub". Etc. I needed ""'s around the word bathtub since it is a word not a variable.
Sergey Alexandrovich Kryukov 24-Feb-14 21:15pm
No problem. It's great that you figured things out. It means that we can work with you and help you in future.
Good luck, call again.
SoMad 25-Feb-14 1:26am
Yes, that is what I was trying to lead you to in my comment to the question.
Actually, don't call it 'word' (because that has a different meaning in programming), call it 'string' instead.

Soren Madsen
Right. I think OP got the idea...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 24 Feb 2014
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100