Basic Sentence maker

Hello guys.
I'm just 12-years old and I have developed a simple sentence making program.
Here's the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
using namespace std;
int main(){
     string name;
     string sports;
     string food;
     cout << "Please enter your name: ";
     cin >> name;
     cout << "Please enter your favorite sport: ";
     cin >> sports;
     cout << "Please Enter your favorite food: ";
     cin >> food;
     system("cls");
     cout << name << " loves to play " << sports << " and loves to eat " << food << endl << endl;
     system("pause");
     return 0;
}


After you input all of your name all-in-all, then. Something like this would show up:

Jackson loves to play Football and loves to eat Spaghetti

Press any key to continue.


Hope you all guys like it!
Last edited on
It's very nice as for beginner!

For next step, try to create random questions asking machine.
Last edited on
closed account (zb0S216C)
xcalibur0645 wrote:
"I'm just 12-years old"

Age carries no weight.

It does its job, but it's very linear; there's no variation. There's a few things I should point out:

1) The way you request input relies on the user to enter only 1 word. If the user wanted to enter their full name, the rest of the input is going to screw up. This is fixed with either std::istream::getline() or std::istream::ignore().

2) The use of system() is frowned upon. While its use in your case isn't immediately threatening, it has hidden dangers that would compromise the safety of your program. See here: http://www.cplusplus.com/forum/articles/11153/

3) Excessive std::istream::endl() invocations can decrease performance. A more efficient alternative is the new-line character ('\n'). Only use std::istream::endl() when you want to force-flush the output buffer.

Perhaps making use of files could expand your current program.

Edit: I just notices you've started another thread which is similar to this one. These forums are for asking questions. However, there are some occasions where users want their code reviewing. That brings me to the question: Do you want your code to be reviewed? I've done that already.

Wazzak
Last edited on
Topic archived. No new replies allowed.