954,506 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Create Function that prints letters, words and sentences

I am in a C++ class and find myself struggling with creating functions that use letters. I have to write out two sentences to the screen. But the assignment is create one function for each letter, space, carriage, return, and punctuation mark. Each word output is controlled by a function (calls each letter, etc function). Each sentence output is controlled by a function (calls each word function). I have read my text book over and over. I have even bought the book C++ for dummies. We have not studied strings or arrays. I know that if I wanted to type out the whole sentence I would have to have code like the following
#include

using std::cout;
using std::endl;

//prototype
void Sentence (void);

void main (){
//call
Sentence ();
}

//definition

void Sentence (void){
cout << I need help << endl;
}

So my question is how do I do this a letter at a time and bring it all together using functions to create letters then words and then sentence :?: Any help will be appreciated :confused:

lakessler1
Newbie Poster
2 posts since Sep 2004
Reputation Points: 11
Solved Threads: 0
 

From the sounds of it, you'd have a bunch of functions like this:

void Print_a()
{
    printf("a");
}


and then to make the word 'apple' you might have:

void Print_apple()
{
    Print_a();
    Print_p();
    Print_p();
    Print_l();
    Print_e();
}


and so on.

Chainsaw
Posting Pro in Training
436 posts since Jun 2004
Reputation Points: 36
Solved Threads: 11
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You