Need help with project due in 2 hours!

Very simple Knock Knock Joke program giving me trouble!

Page 1 of 1

9 Replies - 478 Views - Last Post: 21 September 2009 - 10:35 AM Rate Topic: -----

#1 crackisgood4u  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 53
  • Joined: 11-February 09

Need help with project due in 2 hours!

Post icon  Posted 21 September 2009 - 06:23 AM

 //*************************
//* Project Name: U1-07p.tj
//* Program Name: KK01.cpp
//* Written By: Joshua Thibodeaux
//* Date: 09/12/09
//*
//* This program generates one knock-knock joke and edits the user's responses.
//* Tasks are divided into four functions
//*************************

//**Preprocessor Directives
#include <iostream>
#include <string>
using namespace std;

//Function Proto-types
void getAJoke(string& , string& , string&);
void doJokePart1(string&);
void doJokePart2(string&);

int main()
{
//*****Local Variables and Constants
	string jokePart1;			//joke 1st line
	string jokePart2;			//joke 2nd line
	string jokePunch;			//joke punch line
//*****Program Statements

void getAJoke(string& jokePart1);
void doJokePart1(string& jokePart2);
void doJokePart2(string& jokePart2);


	// display joke punch line
	cout << endl << jokePunch << endl;

	// display closing message
	cout << endl << "Thank you for playing!" << endl;

	system("pause");
	return 0;
}

void getAJoke(string& jokePart1, string& jokePart2, string& jokePunch)
{
	jokePart1 = "knock, knock";
	jokePart2 = "little ole lady";
	jokePunch = "I didn't know you could yodel!";	

}

void doJokePart1(string& jokePart1)
{
	string jokeResp1;

	cout << jokePart1 << endl;
	getline(cin, jokeResp1);

	while(jokeResp1 != "who's there?")
	{
		cout << ("ERROR: " + jokePart1) << endl;
		getline(cin, jokeResp1);
	}

}

void doJokePart2(string& jokePart2)
{
	string jokeResp2;

	cout << jokePart2 << endl;
	getline(cin, jokeResp2);
	
		while(jokeResp2 != (jokePart2 + " who?") )
	{
		cout << ("ERROR: " + jokePart2) << endl;
		getline(cin, jokeResp2);
	}

}


:blink: For some reason my functions are not running, I know one of you :blink: guys will help me, you always do, but can we make it before class!?!?! :crazy: :crazy:

This post has been edited by crackisgood4u: 21 September 2009 - 06:24 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Need help with project due in 2 hours!

#2 galorin  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 86
  • Joined: 17-February 09

Re: Need help with project due in 2 hours!

Posted 21 September 2009 - 06:27 AM

View Postcrackisgood4u, on 21 Sep, 2009 - 05:23 AM, said:

 //*************************
//* Project Name: U1-07p.tj
//* Program Name: KK01.cpp
//* Written By: Joshua Thibodeaux
//* Date: 09/12/09
//*
//* This program generates one knock-knock joke and edits the user's responses.
//* Tasks are divided into four functions
//*************************

//**Preprocessor Directives
#include <iostream>
#include <string>
using namespace std;

//Function Proto-types
void getAJoke(string& , string& , string&);
void doJokePart1(string&);
void doJokePart2(string&);

int main()
{
//*****Local Variables and Constants
	string jokePart1;			//joke 1st line
	string jokePart2;			//joke 2nd line
	string jokePunch;			//joke punch line
//*****Program Statements

void getAJoke(string& jokePart1);
void doJokePart1(string& jokePart2);
void doJokePart2(string& jokePart2);


	// display joke punch line
	cout << endl << jokePunch << endl;

	// display closing message
	cout << endl << "Thank you for playing!" << endl;

	system("pause");
	return 0;
}

void getAJoke(string& jokePart1, string& jokePart2, string& jokePunch)
{
	jokePart1 = "knock, knock";
	jokePart2 = "little ole lady";
	jokePunch = "I didn't know you could yodel!";	

}

void doJokePart1(string& jokePart1)
{
	string jokeResp1;

	cout << jokePart1 << endl;
	getline(cin, jokeResp1);

	while(jokeResp1 != "who's there?")
	{
		cout << ("ERROR: " + jokePart1) << endl;
		getline(cin, jokeResp1);
	}

}

void doJokePart2(string& jokePart2)
{
	string jokeResp2;

	cout << jokePart2 << endl;
	getline(cin, jokeResp2);
	
		while(jokeResp2 != (jokePart2 + " who?") )
	{
		cout << ("ERROR: " + jokePart2) << endl;
		getline(cin, jokeResp2);
	}

}


:blink: For some reason my functions are not running, I know one of you :blink: guys will help me, you always do, but can we make it before class!?!?! :crazy: :crazy:


At a cursory glance, it looks like you are declaring your functions, and defining them. But I can't see where you are actually calling the functions.
Was This Post Helpful? 0
  • +
  • -

#3 crackisgood4u  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 53
  • Joined: 11-February 09

Re: Need help with project due in 2 hours!

Posted 21 September 2009 - 06:29 AM

View Postgalorin, on 21 Sep, 2009 - 05:27 AM, said:

View Postcrackisgood4u, on 21 Sep, 2009 - 05:23 AM, said:

 //*************************
//* Project Name: U1-07p.tj
//* Program Name: KK01.cpp
//* Written By: Joshua Thibodeaux
//* Date: 09/12/09
//*
//* This program generates one knock-knock joke and edits the user's responses.
//* Tasks are divided into four functions
//*************************

//**Preprocessor Directives
#include <iostream>
#include <string>
using namespace std;

//Function Proto-types
void getAJoke(string& , string& , string&);
void doJokePart1(string&);
void doJokePart2(string&);

int main()
{
//*****Local Variables and Constants
	string jokePart1;			//joke 1st line
	string jokePart2;			//joke 2nd line
	string jokePunch;			//joke punch line
//*****Program Statements

void getAJoke(string& jokePart1);
void doJokePart1(string& jokePart2);
void doJokePart2(string& jokePart2);


	// display joke punch line
	cout << endl << jokePunch << endl;

	// display closing message
	cout << endl << "Thank you for playing!" << endl;

	system("pause");
	return 0;
}

void getAJoke(string& jokePart1, string& jokePart2, string& jokePunch)
{
	jokePart1 = "knock, knock";
	jokePart2 = "little ole lady";
	jokePunch = "I didn't know you could yodel!";	

}

void doJokePart1(string& jokePart1)
{
	string jokeResp1;

	cout << jokePart1 << endl;
	getline(cin, jokeResp1);

	while(jokeResp1 != "who's there?")
	{
		cout << ("ERROR: " + jokePart1) << endl;
		getline(cin, jokeResp1);
	}

}

void doJokePart2(string& jokePart2)
{
	string jokeResp2;

	cout << jokePart2 << endl;
	getline(cin, jokeResp2);
	
		while(jokeResp2 != (jokePart2 + " who?") )
	{
		cout << ("ERROR: " + jokePart2) << endl;
		getline(cin, jokeResp2);
	}

}


:blink: For some reason my functions are not running, I know one of you :blink: guys will help me, you always do, but can we make it before class!?!?! :crazy: :crazy:


At a cursory glance, it looks like you are declaring your functions, and defining them. But I can't see where you are actually calling the functions.



Quote

At a cursory glance, it looks like you are declaring your functions, and defining them. But I can't see where you are actually calling the functions.


Are those not function calls under where it is commented "Program statements"
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5678
  • View blog
  • Posts: 22,540
  • Joined: 23-August 08

Re: Need help with project due in 2 hours!

Posted 21 September 2009 - 06:32 AM

No, those are function prototypes.

If you want to succeed, as you say you want to in one of your other non-programming question threads, you're going to need to not wait until the last minute, eh?
Was This Post Helpful? 0
  • +
  • -

#5 TMKCodes  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 48
  • View blog
  • Posts: 440
  • Joined: 21-March 09

Re: Need help with project due in 2 hours!

Posted 21 September 2009 - 07:01 AM

Function prototype

void functionname(std::string message);



Function call.

functionname("Function call");



Remember void function does not return anything so you cant do function call like this, but if the function is some other type than void you can do this.

std::string functionnameReturn = functionname("function call");



This defines the void function.

void functionname(std::string message)
{
	/// Code here!
}



Then again. This would define function what returns something.

std::string functionname(std::string message)
{
	message += " returned";
	return message;
}



If you have problems with c++ syntax you can easily check needed stuff from www.cplusplus.com/doc/tutorial/

This post has been edited by TMKCodes: 21 September 2009 - 07:06 AM

Was This Post Helpful? 0
  • +
  • -

#6 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2209
  • View blog
  • Posts: 9,183
  • Joined: 18-February 07

Re: Need help with project due in 2 hours!

Posted 21 September 2009 - 07:02 AM

I think that you got a little copy/paste happy there. You section:
void getAJoke(string& jokePart1);
void doJokePart1(string& jokePart2);
void doJokePart2(string& jokePart2);

inside of main should look like this:
	getAJoke(jokePart1,jokePart2, jokePunch);
	doJokePart1(jokePart1);
	doJokePart2(jokePart2);

since you want to CALL the functions, not re-declare them, or redefine them etc.

here is the working version:

#include <iostream>
#include <string>
using namespace std;

//Function Proto-types
void getAJoke(string& , string& , string&);
void doJokePart1(string&);
void doJokePart2(string&);

int main()
{
//*****Local Variables and Constants
	string jokePart1;			//joke 1st line
	string jokePart2;			//joke 2nd line
	string jokePunch;			//joke punch line
//*****Program Statements

	getAJoke(jokePart1,jokePart2, jokePunch);
	doJokePart1(jokePart1);
	doJokePart2(jokePart2);


	// display joke punch line
	cout << endl << jokePunch << endl;

	// display closing message
	cout << endl << "Thank you for playing!" << endl;

	system("pause");
	return 0;
}

void getAJoke(string& jokePart1, string& jokePart2, string& jokePunch)
{
	jokePart1 = "knock, knock";
	jokePart2 = "little ole lady";
	jokePunch = "I didn't know you could yodel!";	

}

void doJokePart1(string& jokePart1)
{
	string jokeResp1;

	cout << jokePart1 << endl;
	getline(cin, jokeResp1);

	while(jokeResp1 != "who's there?")
	{
		cout << ("ERROR: " + jokePart1) << endl;
		getline(cin, jokeResp1);
	}

}

void doJokePart2(string& jokePart2)
{
	string jokeResp2;

	cout << jokePart2 << endl;
	getline(cin, jokeResp2);
   
		while(jokeResp2 != (jokePart2 + " who?") )
	{
		cout << ("ERROR: " + jokePart2) << endl;
		getline(cin, jokeResp2);
	}

}

Was This Post Helpful? 0
  • +
  • -

#7 TMKCodes  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 48
  • View blog
  • Posts: 440
  • Joined: 21-March 09

Re: Need help with project due in 2 hours!

Posted 21 September 2009 - 08:50 AM

NickDMax your moderator and isn't giving right away the working code against the rules? He should have got it to work with what i already told.
Was This Post Helpful? 0
  • +
  • -

#8 KYA  Icon User is offline

  • su wtf -am -i /doing/with/my/life
  • member icon

Reputation: 2979
  • View blog
  • Posts: 19,035
  • Joined: 14-September 07

Re: Need help with project due in 2 hours!

Posted 21 September 2009 - 09:02 AM

Mot really. He provided is current attempt, thus, code can be provided.
Was This Post Helpful? 0
  • +
  • -

#9 TMKCodes  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 48
  • View blog
  • Posts: 440
  • Joined: 21-March 09

Re: Need help with project due in 2 hours!

Posted 21 September 2009 - 10:21 AM

Okey i did not know that. I would have myself given the code then. :) Thanks.
Was This Post Helpful? 0
  • +
  • -

#10 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2209
  • View blog
  • Posts: 9,183
  • Joined: 18-February 07

Re: Need help with project due in 2 hours!

Posted 21 September 2009 - 10:35 AM

He said he needed it fast and the corrections really were simple and the kind of knuckle headed oopse that I myself might do when rushing to meet a deadline. Sometimes your eyes don't see the code so much as your mind tells you that you did all the steps in the right order.

That and he did attempt the problem. He did provide code.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1