cout problems...

Posts 1–15 of 21 · Page 1 of 2
cout problems...
EDIT

fixed
endl to divide them into different lines.

[php]
cout <<"Line1"<<endl;
cout <<"Line2"<<endl;

[/php]
You could also do it this way
[php]cout << "Text\n" << "More Text\n" << "Even more Text\n";[/php]

adding[php]\n[/php] means new line too.

Put it Right before you close the Qoute. You can also use it standalone like this
[php]cout << first_name << " " << last_name << '\n';[/php]

You can also use the endl also
Quote Originally Posted by Auxilium View Post
You could also do it this way
[php]cout << "Text\n" << "More Text\n" << "Even more Text\n";[/php]

adding[php]\n[/php] means new line too. You can also use the endl also
I love you.
Heres what i mean


You may also do this
[php]cout << "This is the first line\nThis is the 2nd line\nThis is the last line\n";[/php] But its harder to read
Quote Originally Posted by Auxilium View Post
Heres what i mean


You may also do this
[php]cout << "This is the first line\nThis is the 2nd line\nThis is the last line\n";[/php] But its harder to read
I know that... What I'm asking, is

It's supposed to ask for a random word, then a number

what it does is say "say a random word say a number" and then when I push anything it continues on to the next question...

What can I put after cout to get it to STOP joining lines... display 1 line wait for input continue
[php]cout << "Say a random word\n";
cin >> word;
cout << "Say a random number\n";
cin >> number;[/php]?
[php]
#include <iostream>
#include <string>
#include <sstream>
#include <dos.h>
using namespace std;

int main()
{
int thisIsANumber;
char yesOrNo;
char likeShitTacos;
char BelgianOrEggos;
char strawberry;
char syrup;
string ITSASTRING; // empty string, used for transfering variables
string firstname; // second string, used for first name
string lastname; // third string, used for last name
int age; // int, used for age
string randomword;
int favouritenumber;

cout << "Hi, what is your FIRST name?" << endl;
getline (cin,ITSASTRING); // getting the input from this line and inputting it into ITSASTRING
stringstream(ITSASTRING) >> firstname; // transferring data from ITSASTRING to firstname
cout << "Alright " << firstname << " what is your last?";
getline (cin,ITSASTRING); // getting the input from this line and inputting it into ITSASTRING
stringstream(ITSASTRING) >> lastname; // transferring data from ITSASTRING to lastname

cout << "alrighty then " << firstname<<" " <<lastname <<", how old are you?" << endl; // displaying firstname lastname and asking how old
cin >> age; // the usual cin >> age
if (age < 20) { // if age is less than 20 do the following
cout << "Hi " << firstname<< " " <<lastname << ", welcome to my application!\n type some random word!"<< endl;
getline (cin,ITSASTRING);
stringstream(ITSASTRING) >> randomword;
}
else { // age was more than 20 so we do the following
cout << "Hi " << firstname<<" " <<lastname <<" sorry, but you are too old." << endl;
}

cout << "thats the first word that came to your mind? weird...\n"<< endl;
system("cls");
cout << "Enter a number"<<endl;
getline (cin,ITSASTRING);
stringstream(ITSASTRING) >> thisIsANumber;

cout << "was this your favourite number? (y/n)"<<endl;
getline (cin,ITSASTRING);
stringstream(ITSASTRING) >> yesOrNo;

if(yesOrNo == 'y')
{
cout << "oh, well that was an interesting favourite number.\n"<<endl;
}
else if(yesOrNo == 'n')
{
cout << "oh... what is your favourite number?\n"<<endl;
getline (cin,ITSASTRING);
stringstream(ITSASTRING) >> favouritenumber;
}
else
{
cout << "that wasn't an answer, genius"<<endl;
}
cout << "Do you like waffles?!?!?!!? (y/n)\n"<<endl;
getline (cin,ITSASTRING);
stringstream(ITSASTRING) >> likeShitTacos;
if(likeShitTacos == 'y')
{
cout << " I knoww they are awesome!!!! Belgian or Eggos? (b/e)\n"<<endl;
getline (cin,ITSASTRING);
stringstream(ITSASTRING) >> BelgianOrEggos;
if(BelgianOrEggos == 'b')
{
cout << "yeaaah those are the best... with strawberrys and whipped cream right?(y/n)"<<endl;
getline (cin,ITSASTRING);
stringstream(ITSASTRING) >> strawberry;
if(strawberry == 'y')
{
cout << "mmmm waffles with strawberries and whipped cream... mmmmmmmm"<<endl;
}

else if(strawberry == 'n')
{
cout << "ewwwww... You still use syrup though right? (y/n)"<<endl;
getline (cin,ITSASTRING);
stringstream(ITSASTRING) >> syrup;
if(syrup == 'y')
{
cout << "good... I was worried"<<endl;
}
else if(syrup == 'n')
{
cout << "WTF MAN!!! PLAIN WAFFLES?!?!?! YOUR CRAZY"<<endl;
}
else
{
cout << "one more answer and thats it... Your booted off of this I swear."<<endl;
}
}
else
{
cout << "STOP ANSWERING THAT!!!!!!!!!!!!!"<<endl;
}

}
else if(BelgianOrEggos == 'e')
{
cout << "reaally? Eggos more then Belgians? You've clearly never had a belgian waffle before..."<<endl;
}
else
{
cout << "that wasn't an answer, stop saying random letters... it makes me confused"<<endl;
}
}
else if(likeShitTacos == 'n')
{
cout << "Whatt?!?! you don't like waffles? gtfo...\n"<<endl;
}
else
{
cout << "This wasn't a choice, gtfo\n"<<endl;
}

cout << "well, that'll be all for now. I may have a few updates to this fun little game in the future. Maybe in a .exe "<<endl;
cin.get();
return 0;
}
[/php]


[php]

cout << "Hi " << firstname<< " " <<lastname << ", welcome to my application!\n type some random word!"<< endl;
getline (cin,ITSASTRING);
stringstream(ITSASTRING) >> randomword;
}
else { // age was more than 20 so we do the following
cout << "Hi " << firstname<<" " <<lastname <<" sorry, but you are too old." << endl;
}

cout << "thats the first word that came to your mind? weird...\n"<< endl;
system("cls");
cout << "Enter a number"<<endl;
getline (cin,ITSASTRING);
stringstream(ITSASTRING) >> thisIsANumber;

[/php]

This is where it starts messing up... It uses the same code for here as everywhere else but this is where it messes up... Try running the entire code and you'll see what I mean...
I see youre using the thing if elses and some variables i posted on your other thread xD . Like when you enter age it skips something?

Mind if i rewrite it simpler?
Quote Originally Posted by Auxilium View Post
I see youre using the thing i posted on your other thread xD . Like when you enter age it skips something?
yeah somewhat, I copied, pasted and re-wrote it... After I learned what it all meant

But just look through the code, make sure there isn't anything that'll scare ya then run it... but yeah, right after I enter age, it skips the a bunch...
Quote Originally Posted by VvITylerIvV View Post
yeah somewhat, I copied, pasted and re-wrote it... After I learned what it all meant

But just look through the code, make sure there isn't anything that'll scare ya then run it... but yeah, right after I enter age, it skips the a bunch...
Well..I never used the [php]getline(cin,____)[/php] thing so im not sure...
Quote Originally Posted by Auxilium View Post


Well..I never used the [php]getline(cin,____)[/php] thing so im not sure...
Yeah, I learnt that and I'm practicing with it here. But as for my problem? it skips... is there a solution to that?
Quote Originally Posted by VvITylerIvV View Post
Yeah, I learnt that and I'm practicing with it here. But as for my problem? it skips... is there a solution to that?
Idk..I could make it work my way /
Quote Originally Posted by Auxilium View Post


Idk..I could make it work my way /
you'd be using cin >> wouldn't you? I don't wanna use that and plus, it was doing that when I had it as cin anyways... it only happens at certain parts of the code, which annoys me because the code is exactly the same at other parts that it doesn't skip at.
Quote Originally Posted by VvITylerIvV View Post
you'd be using cin >> wouldn't you? I don't wanna use that and plus, it was doing that when I had it as cin anyways... it only happens at certain parts of the code, which annoys me because the code is exactly the same at other parts that it doesn't skip at.
Maybe you made a mistake with your else if
Posts 1–15 of 21 · Page 1 of 2

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us