What did I do wrong here?

I just started learning C++ (any code for that matter, I'm an sound guy by trade) and this is day 5 in my attempts at learning.

Everything seems to be ok here when I run the program but I can figure out how to have the lines after the functions appear on a new line.

#include <iostream>

using namespace std;
typedef unsigned short int USHORT;

const USHORT myAge = 24;
const USHORT myTime = 72;

void thirdlinefunction() // this is the third line of text
cout << "This is the third line function\n";
cout << "Still the third line function :)";

int arithmeticfunction() // this is the arithmetic function used near the end
cout << (myAge * myTime / 6);

void fifthlinefunction() // this is the fifth line of text
cout << "This is the fifth line function\n";
cout << "Still the fifth line function";
/* This is a test
Just a test of typing on a few lines

int main()
cout << "First line created in your biggest program yet \n";
cout << "Second line created without a problem\n";
cout << "Love you lots emmybear mwuah\n";
cout << "Almost done, just one more function to initiate \n";
cout << "3, 2, 1 ... GO\n";
cout << "All done and well done.\n";
cout << "LOVE YA EMMYBEAR :)";
char response;
cin >> response;
return 0;


Say this is suppose to be the 3rd, 4th and 5th lines of what the program prints out:

This is the third line function
Still the third line function
Love you lots emmybear mwuah

Here's what happens:

This is the third line function
Still the third line functionLove you lots emmybear mwuah

As you can see, I need to figure out how to continue the new function on the new line. Let me know if anything is glaringly wrong in this. Take care and thank you :) Also how am I progressing? I feel like for 5 days I'm doing alright making this from scratch ... hopefully :P And yes I made this for my girl lol

Last edited on
Each call to 'cout' will print the text in the same line. If you want to move cursor to the next line, end text string with '\n' (a new line symbol), as you do in most cases, except those, which seem to be the problem.

Instead of '\n' character you may also use '<< endl' symbol, like in your arithmeticfunction:
void arithmeticfunction() 
cout << (myAge * myTime / 6) << endl;
Last edited on
in ur thirdlinefunction put a "\n", where u cout<<"still the third line func,"
I suggest if you want the line to stay on that line for the next output to put << std::flush; at the end instead of just a semi-colon (even though most compiler automatically flush). And to move to the next line as the others have mentioned you can use << "Stuff"<< '\n' << std::flush;
or << "Stuff\n" << std::flush;
or even << "Stuff" << std::endl; endl puts a new line then flushes

Oh and try not to use global variables like you are...
and I wouldn't recommend using namespace std; especially in the global scope you are only using std::cout so if you "must" do it the "using" method put using std::cout inside the functions that are actually using it but I would recommend just to put std:: before everything that is in the namespace it is not just cout it is also a lot of other things like strings, vectors, endl, getline, cin, ect...
Last edited on
Thanks everyone :) Fixed it right up
Topic archived. No new replies allowed.