Messed up...

Posts 1–9 of 9 · Page 1 of 1
Messed up...
Code:
#include <iostream>
using namespace std;

int main()
{
    int length;
    length = 7;
    cout << "The length is";
    cout << length;
    system("pause");
    return 0;
}
and this is wat i get...



i want the (press any key to continue...) in the second line please help me.

ALSO MODS: CAN U PLEASE MAKE A HELP THREAD AND STICKY IT PLEASE
Quote Originally Posted by Zhhot View Post
Code:
#include <iostream>
using namespace std;

int main()
{
    int length;
    length = 7;
    cout << "The length is";
    cout << length;
    system("pause");
    return 0;
}
and this is wat i get...



i want the (press any key to continue...) in the second line please help me.

ALSO MODS: CAN U PLEASE MAKE A HELP THREAD AND STICKY IT PLEASE
Well, if you want only the "press any key to continue" to appear on the next line, you can use cout << endl;
For example:
Code:
#include <iostream>
using namespace std;

int main()
{
    int length;
    length = 7;
    cout << "The length is";
    cout << length;
    cout << endl;
    system("pause");
    return 0;
}
Or you could do it like this

Code:
#include <iostream>
using namespace std;

int main()
{
    int length;
    length = 7;
    cout << "The length is";
    cout << length << endl;
    system("pause");
    return 0;
}
However if you had a string there is another option, the newline character (\n), for example
Code:
#include <iostream>
using namespace std;

int main()
{
    int length;
    length = 7;
    cout << "Yay random sentence\n";
    cout << "Yay thanks to the newline character, i'm by myself\n";
    system("pause");
    return 0;
}
Everything from the newline character onwards, is put into a new line.
Another example:
Code:
cout << "there is a new\nline in the middle of newline!!";
Would appear in the console as
Code:
there is a new
line in the middle of newline!!
oh thanks man, that explains so much
Quote Originally Posted by Zhhot View Post
oh thanks man, that explains so much
No problem, glad to help =).
hey zeco, i was looking at ur goal list, and noticed something wierd. y didnt u tick mark "Have a good grasp of C++", i think ur pretty good
Quote Originally Posted by Zhhot View Post
hey zeco, i was looking at ur goal list, and noticed something wierd. y didnt u tick mark "Have a good grasp of C++", i think ur pretty good
Haha, well because i still have a lot to learn. I'm probably going to tick it when i finish this C++ book (C++ primer plus). I just happen to know more than the book has taught so far cause when i feel like doing stuff, i just research how regardless of whether or not i'll eventually learn it in the book. I'm a bit impatient that way, and i love to learn =)
You also could do this

Code:
#include <iostream>
using namespace std;

#define NEWLINE '\n'

int main()
{
    int length;
    length = 7;
    cout << "The length is";
    cout << length;
    cout << NEWLINE;
    system("pause");
    return 0;
}
You can change the NEWLINE to whatever you want, I wouldn't actually recommended this by the way. endl is easier in my opinion
ty royal, im starting to love mpgh, every1 is so helpfull =)
Quote Originally Posted by Zhhot View Post
ty royal, im starting to love mpgh, every1 is so helpfull =)
Your welcome, theres so many ways to do one thing
and I love it here too. And that NEWLINE thing I just learned lol
Posts 1–9 of 9 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

Talk with us