I need help fixing this I help getting errors

#include <cstdlib>
using namespace std;

void show_word (string);

int main ()

{
show_word ("hello");
system ("PAUSE");
return 0;
}


void show_word (char);

{
char InName;
cout << "Enter your name " << endl;
cin >> InName >> endl;

show_word ("hello");
show_word ( string InName);

}

Recommended Answers

All 8 Replies

void show_word (string); then you have void show_word (char); char InName; // shouldn't this be string? cin >> InName >> endl; // don't put endl here You are also calling show_word from within itself. This is recursive and will never end.


void show_word (char);

{
char InName;
cout << "Enter your name " << endl;
cin >> InName >> endl;

show_word ("hello");
show_word ( string InName);

}

this will produce recursion, show_word calling show_word and never end and thats just the beginning

Alrighty! working on changes now

anybody got some solutions im drawing blanks

#include <cstdlib>
using namespace std;

void show_word (string);

int main ()

{
         show_word ("hello");
         system ("PAUSE");
         return 0;
}


void show_word (char); // dont put semicolono here it will produce error and the type parameter is not the                  
                                   // same like it's declaration then there isnt name of paramater there
{
          char InName;
          cout << "Enter your name " << endl;
          cin >> InName >> endl; // dont put endl on this, because endl make a new line to the output

          show_word ("hello");  // this make recursion
          show_word ( string InName); // this make recursion and error maybe because u declare  
                                                     // same parameter, first as char, second as string
}

Pay close attention to the comments.

//#include <cstdlib> This library is not apllicable for your needs
// http://www.cplusplus.com/reference/clibrary/cstdlib/
// Follow the link for more information on libraries

#include <string>  // include the string library when working with strings
#include <iostream> // this library includes functions cin and cout

using namespace std;

void show_word (string);

int main ()
{
	string InName; // declares InName as type string

// Hello could be dealt with using a simple cout << "Hello "
// It would be more useful if the function accepted the person's name
// or just accepted nothing at all depending on how you want to structure your program

	cout << "Enter your name " << endl;
	cin >> InName;
	show_word (InName); // passes the value in InName to show_word function
system ("PAUSE");
return 0;
}

// The function protoype and implementation must match. 
// You declared type string in your prototype and in your implimentation accepted type char. string is easier to work because it does not need pointers or arrays.
// When defining function implimentations do not use semi-colons.

void show_word (string InName)  // Parameter variables can be declared here but types + number must match with the prototype.
{

// endl is used to create a new line on the screen. "cout << endl;" would be appropriate
cout << endl;
cout << "Hello " << InName; // this prints the literally "Hello" followed by the value in "InName"

//show_word ("hello"); // all this does could do would be to store the world hello
//show_word ( /*string*/ InName); 

}

hmmm...intresting

Thank you much you guys

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.