I need help on class work!!

Started by
8 comments, last by pi_equals_3 16 years, 6 months ago
I know, wrong place most likely, but I have a problem with my Visual C++ assignment (on something not covered by the teacher). We have to do some variable work with the cout and cin commands, but here's my problem, and it's I can't get a raw_input thing like they have it in Python. Source Code:
#include <iostream>
using namespace std;

int main()
{
/* Variable Assignment 3

Create a "Mad Libs" program. 

Your first step should be to write a short story. Leave out some of the words so that the user can fill in the blanks. The catch is that you ask the user for the missing words before they are allowed to read the story.

Second, declare and initialize at least 15 variables. Most of these 
should be words, but some may be numbers. 

Third, ask the user to input each word/number. For example:

Enter a color:
Enter a noun:
Enter an adverb:

Once all the words have been entered, plug them into your story and print the story to the screen with the user's words included.

For example:

cout << "Once upon a time, there was a " << noun1 << ". This particular " << noun1 << " was very " << adjective1 << "." << endl << endl;

*/
	char name1 [20] = "#";
	char weapon1 [28] = "#";
	char item1 [30] = "#";
	char name2 [20] = "#";
	char weapon2 [28] = "#";
	char item2 [30] = "#";
	char noun1 [18] = "#";
	char verb1 [24] = "#";
	char noun2 [18] = "#";
	char verb2 [24] = "#";
	char noun3 [18] = "#";
	char verb3 [24] = "#";
	char color [12] = "#";
	char characterClass [48] = "#";
	char badGuy [30] = "#";
	char noun4 [18] = "#";
	char verb4 [24] = "#";
	char moral [200] = "#";

	cout << "Enter a full boy's name (with underscores):  ";
	cin >> name1;
	cout << "Enter a weapon name (same as above for all of these name things):  ";
	cin >> weapon1;
	cout << "Enter an item name:  ";
	cin >> item1;
	cout << "Enter another full name:  ";
	cin >> name2;
	cout << "Enter another weapon name:  ";
	cin >> weapon2;
	cout << "Enter another item name:  ";
	cin >> item2;
	cout << "Enter a noun:  ";
	cin >> noun1;
	cout << "Enter a verb:  ";
	cin >> verb1;
	cout << "Enter another noun:  ";
	cin >> noun2;
	cout << "Enter another verb:  ";
	cin >> verb2;
	cout << "Enter another noun:  ";
	cin >> noun3;
	cout << "Enter another verb:  ";
	cin >> verb3;
	cout << "Enter a robe color:  ";
	cin >> color;
	cout << "Enter a character class:  ";
	cin >> characterClass;
	cout << "Enter the name of a villain you would love to defeat:  ";
	cin >> badGuy;
	cout << "Enter a noun:  ";
	cin >> noun4;
	cout << "Enter a verb:  ";
	cin >> verb4;
	cout << "Enter a moral for the story of fighting:  ";
	cin >> moral;

	cout << "	CRASH!!!!  THUD!!!!  Who would have thought that " << name1 << " would land in the house of Dr. Viper?!  And also, who knew that he would inherit the legendary weapon of destruction, the " << weapon1 << "?!" << endl;
	continue 0;
	cout << "	\"Who is that who lands in my HOUSE and ruins my roof?!?!\"  So " << name1 << " apologized and then felt woozy.  Just then, a weird person called " << badGuy << " came by and along with this person another person named " << name2 << " showed up." << endl;
	continue 0;
	cout << "	\"Ahhh,\" said " << badGuy << " in a weird manner, \"you must have been a normal human in a different world where there are no cat humans...  is that right, " << name1 << "?\"  Just then, Dr. Viper injected " << name1 << " with a shot called " << item1 << "." << endl;
	continue 0;
	cout << "	\"Why not let the guy sleep now?  Now please get out of the house, before I send my GIANT BACTERIA at you, and have it eat you!!\"  At the mention of it's name, the monster known as the Giant Bacteria appeared with great speed and might.  \"Not now, precious, not now.  Wait for until the second shot is given,\" said Dr. Viper, \" If they haven't left yet." << endl;
	continue 0;
	cout << "	So " << name1 << " was given a bed to sleep in and a second shot...  with the two gone from Dr. Viper's house.  When " << name1 << " was still sleeping, Dr. Viper was doing some research on citizens of the city that was nearby, known as \"Mega-Kat City\"." << endl;
	continue 0;
	cout << "	\"Next!!\" Dr. Viper asked for a certain " << noun1 << " this time for an even more in-depth test.  " << verb1 << "!!  \"AAAHHHGGGHHH!!!!\" went all the patients, though no one heard it in the other room, due to the testing room being sound-proofed.  " << noun2 << " was the next unlucky one.  " << verb2 << "!!!!  " << noun3 << "was another luckless person.  " << verb3 << "!!!!  \"NEXT!!\"  " << noun4 << " tried to resist but was dragged in by the Dr.  " << verb4 << "!!!!" << endl;
	continue 0;
	cout << "	Meanwhile, " << name1 << " was having a really peculiar dream, with some weird things going on.  \"Father...  where are you?  I was looking all over for you in the past!!  It's me, your daughter, Kiala!!\"  \"Uhhhhh...  wha...  what's happening to me?\" asked " << name1 << ".  \"I don't have a daughter at a-\"  but got interrupted by " << name2 << ".  \"This is your daughter from the future.  Get used to it now before anything else happens.  Oh, by the way, you need to wake up now.\"  So " << name1 << "listened to what he needed to first and woke up." << endl;
	continue 0;
	cout << "	When he woke up, " << name1 << " heard nothing, except for his own breathing.  He noticed that he could see without his now-broken glasses the correct way.  He also noticed a weird presence around him like a mystic energy around himself.  Whatever that meant, he knew that " << name2 << " knew what was best and what was right in this situation, which is that he needed to destroy the monsters made by Dr. Viper.  \"Seeing that you have a " << color << " robe, it is wise that you consider yourself a member of the Organization, and not just an average person.\"  That was what " << name2 << " had said earlier.  No going back now as a " << characterClass << "." << endl;
	continue 0;
	cout << "	KER-CRITICAL!!  Now " << name1 << " knew how to fight these monsters after a very little amount of time.  \"FREEZE, CRIMINAL!!  YOU'RE UNDER ARREST FOR USING A WEAPON UNAUTHORIZED BY THE GOVERNMENT AND THE ENFORCERS, THE LAW ENFORCEMENT OF THE CITY!!\"  Before he could do it, however, a monster with it's neck at the top point reaching the air plane with the commander and higher than that.  No, I'm not even joking, the monster really is THAT TALL!!  Not that it matters, though, because the monster died by beheading...  from the " << weapon1 << "'s power.  I'm being serious again." << endl;
	continue 0;
	cout << "	Now the moral of the story is this:  " << moral << "." << endl;

	return 0;
}
My main problem is that I tried return 0s first and that didn't work. Now I have an error with all the continue 0s combined. Not only am I behind in class, but I think I used a command from a different part of class that is ahead of me. Is anyone willing to help?
Most likely the n00biest programmer out there. I need a website soon so that I can share my projects with you (when done with my projects).
Advertisement
Maybe I'm missing something, but... what exactly are you trying to do with those "continue 0" lines? (They are not correct... sorry, since it's school work we have to be careful about saying too much)


And, for what its worth, the continue statement is used within loops, which I doubt you've covered yet.
The continue statement forces transfer of control to the controlling expression of the smallest enclosing do, for, or while loop. You don't need anything of that sort here. And return statement is used for returning a value from the function. You'll learn about them both as you progress through your course.

So, do we need them here in your program?
Yeah, I have no clue why you're putting the continue 0; statement. Get rid of all of them and it should work.
Here's what I meant to say: Hey guys, do you know about "A RAW_INPUT COMMAND IN C++", where one needs to press a key and it goes on? I need to know how to do a command style that's in Python and maybe in C++ by the end of the school week.

Anybody have any ideas?
Most likely the n00biest programmer out there. I need a website soon so that I can share my projects with you (when done with my projects).
you can use cin to make the program wait until they press enter...
OK. I have very little clue about Python. But from what little I recollect, raw_input() is very similar what you have done here. It would be little helpful if you elaborated what exactly you want to do, cause I am unable to understand you.

In case you wanted this, (I doubt it though) this is how you do input output in C++

Say you have a variable age, which is int. ie. int age;

You want to print the prompt "enter your age" Then use, cout<<"Enter your age";

To read it into the variable age use cin>>age; That is the user enters whatever 20 or 100 at the above prompt on the screen.

To print it on the screen again use, cout<<"Your age is:"<<age;

Sorry if this wasn't in the least helpful.
I think what he's saying is, "I don't care that my code is completely incorrect, just tell me how to make my application pause before exiting."

So ignoring the major "WTF?!" with all the continue 0; as someone else has suggested you can make your application pause with cin.

Example.
int dummy;
cout << "Press enter to continue...\n";
cin >> dummy;

I believe that will do what you're asking for. It wont however fix your code.

Hello,

What's with the continue statements? From your second post I think you are trying to say how do I pause the program until the user hits a key, maybe like enter, and it then continues until it is asked again. Well since you said this is a school project I won't directly tell you, but I would advise to go to google and look up on it. I will offer a hint for you. It is something dealing with cin.getline() function, and there is something else you need to use from cin too. That is all the help I can offer.

Sincerely,
Carl J. Loucius
Quote:Original post by acddklr07
Hello,

What's with the continue statements? From your second post I think you are trying to say how do I pause the program until the user hits a key, maybe like enter, and it then continues until it is asked again. Well since you said this is a school project I won't directly tell you, but I would advise to go to google and look up on it. I will offer a hint for you. It is something dealing with cin.getline() function, and there is something else you need to use from cin too. That is all the help I can offer.

Sincerely,
Carl J. Loucius


acddklr07 is absolutely correct. You're not looking for a way to pause the program to wait for input. Using cin properly will do this. The problem lies in the way you've written your input. I'm not going to give you answers, but perhaps you should look at any material you have from your class regarding user input (especially with strings).

This topic is closed to new replies.

Advertisement