Would look. But there are 2 things preventing me.
1. Too long
2. You using dat [php]getline(cin,ITSASTRING);[/php] again
I tried to clean up my code, made a few functions, a whole new header for variables. And it all worked fine. Until I tried to use the Frestart function from functions.h in TBQ.cpp.
functions.h
[php]
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int aaaa;
void Felse(){
cout << "that wasn't an answer...\n";
}
void test (string a, char c[40], char e[40] ){
if(a == "y"){
cout << c << endl;
}
else if(a == "n"){
cout << e << endl;
}
else { Felse(); }
}
void Frestart (string ITSASTRING, string restart){
cout <<"time to end this game... if you want "<<endl;
cout << "would you like to play again? (y/n)"<<endl;
getline (cin,ITSASTRING);
stringstream(ITSASTRING) >> restart;
if (restart == "y"){ // if they want to restart, play again
cout << "alright, here we go!!!!"<<endl;
}
else if (restart == "n"){ // if they don't ensure they don't
cout << "I'm going to ask again, just for safety's sake. Would you like to play again? (y/n)"<<endl;
getline (cin,ITSASTRING);
stringstream(ITSASTRING) >> restart;
if (restart == "y"){
cout << "alright, I'm going to restart it for you"<<endl;
}
else if (restart == "n"){
exit(0);
}
else {
cout << "sorry, what was that?\ndid you want to replay or not? (y/n)"<<endl;
getline (cin,ITSASTRING);
stringstream(ITSASTRING) >> restart;
if (restart == "y"){
cout << "alright, going to restart it for you"<<endl;
}
else{
exit(0);
}
}
}
}
[/php]
variables.h
[php]
#include "functions.h"
int thisIsANumber; // used for random number
string yesOrNo; // used for favourite number
string likeShitTacos; // used for waffles
string BelgianOrEggos; // used for belgian or eggos
string strawberry; // used for strawberries and whipped cream on belgian waffles
string syrup; // used for syrup on belgian waffles
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; // used for random word
int favouritenumber; // used for favourite number
string girlsorboys; // likes girls or boys
string boyorgirl; // is a boy or girl
string tylerishot; // am I hot? obviously...
string girlright; // your a girl right?
string justinbieber; // you better not like justin bieber
string pancakes; // like pancakes?
string likewinter; // like winter?
string kissedcody; // ever kissed cody miller?
string Cgirl; // girl kissed cody right?
string favseason; // fav season
string restart; // restart game?
string areyousure; // sure you don't wanna restart?
string AREyousure; // absolutely sure you wanna quit?
string computer; // like the computer
string boyORgirlfriend; // have a boyorgirlfriend
string girlORboyfriend; // boy or girlfriend?
string boyfriendname; // boyfriend's name
string girlfriendname; // girlfriend's name
string picklesandpopcorn; // like pickles and popcorn?
string eathair; // eat your hair?
string smoothies; // like smoothies?
string hotdogs; // like hotdogs?
string princesses; // like princesses?
[/php]
tbq.cpp
[php]
#include "functions.h"
#include "variables.h"
using namespace std;
int main()
{
do {
system("cls");
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
getline (cin,ITSASTRING);
stringstream(ITSASTRING) >> 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!\ntype 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;
exit(0);
}
cout << "thats the first word that came to your mind? weird...\n"<< endl;
cout << "Enter a number"<<endl;
getline (cin,ITSASTRING);
stringstream(ITSASTRING) >> thisIsANumber;
cout << "was this your favourite number?"<<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?\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 << "do you like girls or boys? (g/b)"<<endl;
getline (cin,ITSASTRING);
stringstream(ITSASTRING) >> girlsorboys;
if (girlsorboys == "g")
{
cout << "Oh, great, I do as well. You are a boy or a girl? (b/g)"<<endl;
getline (cin,ITSASTRING);
stringstream(ITSASTRING) >> boyorgirl;
if (boyorgirl == "g"){
cout << "oh..."<<endl;
}
else if (boyorgirl == "b"){
cout << "oooohhh good "<<endl;
}
else{
cout << "don't push the wrong buttons please!! you're going to drive me insane!!!!"<<endl;
}
}
else if (girlsorboys == "b")
{
cout << "ewwwww are you a boy or a girl... (b/g)"<<endl;
getline (cin,ITSASTRING);
stringstream(ITSASTRING) >> boyorgirl;
if (boyorgirl == "b"){
cout << "ok then......\n";
}
else if (boyorgirl == "g"){
cout << "ok, good "<<endl;
}
else{
cout << "really... stop with the insane clicking of these random buttons"<<endl;
}
}
cout << "Do you think tyler is hooooot??? (y/n)"<<endl;
getline (cin,ITSASTRING);
stringstream(ITSASTRING) >> tylerishot;
if (tylerishot == "y"){
cout << "alrighty then... your a girl right? (y/n)"<<endl;
getline (cin,ITSASTRING);
stringstream(ITSASTRING) >> girlright;
if (girlright == "y"){
cout << "we should like, totally go out sometime!! "<<endl;
}
else if (girlright == "n"){
cout << "umm... ok then... awkwardddd"<<endl;
}
else{
cout << "don't. push. the. wrong. button. again.!!!!!"<<endl;
}
}
else if (tylerishot == "n"){
cout <<"WHATT?!?! IM ABSOLUTELY 100% HOOTTT. get a life kid"<< endl;
}
else{
cout <<"STOP HITTING THAT BUTTON, JESUS CHRIST."<<endl;
}
cout << "Do you like justin bieber? (y/n)"<<endl;
getline (cin,ITSASTRING);
stringstream(ITSASTRING) >> justinbieber;
if (justinbieber == "y"){
exit(0);
}
else if (justinbieber == "n"){
cout << "FINALY, SOMEBODY WHO'S HUMAN!"<<endl;
}
else{
cout << "WTF?! DO YOU LIKE HIM OR NOT... (y/n)"<<endl;
getline (cin,ITSASTRING);
stringstream(ITSASTRING) >> justinbieber;
if (justinbieber == "y"){
cout <<"get a life..."<<endl;
system ("pause");
exit(0);
}
else if (justinbieber == "n"){
cout << "THANK GOD!!!!"<<endl;
}
else{
cout << "really? again? your getting booted."<<endl;
system ("pause");
exit(0);
}
}
cout << "do you like pancakes??? (y/n)"<<endl;
getline (cin,ITSASTRING);
stringstream(ITSASTRING) >> pancakes;
if (pancakes == "y"){
cout <<"awesome you rock!"<<endl;
}
else if (pancakes == "n"){
cout << "you don't like pancakes??? where are you from? the moon?"<<endl;
}
else {
cout << "Can you please not hit the wrong button next time? It's quite annoying you know..."<<endl;
}
cout << "Do you like winter? (y/n)"<<endl;
getline (cin,ITSASTRING);
stringstream(ITSASTRING) >> likewinter;
if (likewinter == "y"){
cout << "OEMGEE I ABSOLUTELY LOVE WINTER, WE HAVE SO MUCH IN COMMON )"<<endl;
}
else if (likewinter == "n") {
cout << "ewww... what do you like?\n(s) Summer\n(S) Spring\n(f) Fall" <<endl;
getline (cin,ITSASTRING);
stringstream(ITSASTRING) >> favseason;
if (favseason == "s"){
cout << "really, summer is your favourite... interesting. I hate that season "<<endl;
}
else if (favseason == "S") {
cout << "yeah, springs a pretty good season as well I guess..."<<endl;
}
else if (favseason == "f") {
cout << "Fall, thats an Ok season I guess... Playing in the leaves is pretty fun I guess."<<endl;
}
else{
cout << "Ok... DON'T PUSH THE WRONG BUTTON. I'm seriously going to exit(0); you...."<<endl;
}
}
else {
cout <<"STOP THAT"<<endl;
}
cout <<"Have you ever kissed Cody Miller? (y/n)"<<endl;
getline (cin,ITSASTRING);
stringstream(ITSASTRING) >> kissedcody;
if (kissedcody == "y"){
cout <<"Please tell me your a girl...(y/n)"<<endl;
getline (cin,ITSASTRING);
stringstream(ITSASTRING) >> Cgirl;
if (Cgirl == "y"){
cout <<"oh... how interesting, I didn't know he's kissed YOU."<<endl;
}
else if (Cgirl == "n"){
cout << "oh... I'll be talking to him later"<<endl;
}
else {
cout << "are you going to stop hitting the wrong button any time soon?"<<endl;
}
}
else if (kissedcody == "n"){
cout <<"Well, I could've figured THAT out..."<<endl;
}
else{
cout<<"FOR **** SAKES STOP THAT..."<<endl;
}
Frestart (ITSASTRING, restart);
}
while(restart == "y");
return 0;
}
[/php]
when it gets to Frestart(ITSASTRING, restart); it does all the code in the function Frestart then closes the program... I want it to do all the code in the function then continue with the program (do while loop)
I gotta go to sleep now, if you wanna help then just run this in your compiler and you'll see what my problem is
Favourite quotes:
Definition of computing: The use or operation of computers.Code:I don't need easy, I just need possible. ~ Me There are three birds on a fence. Two decide to fly away, how many are left? Three, just because you decide to do something doesn't mean you've done it. ~ Don't know who said this Do not go where the path may lead, go instead where there is no path and leave a trail. ~ Ralph Waldo Emerson
Turning on my computer = computing = programming
LAWLFAIL
Would look. But there are 2 things preventing me.
1. Too long
2. You using dat [php]getline(cin,ITSASTRING);[/php] again
your problem is at the FRestart function.
you can't send a parameter like that if you want it to be changed inside the function.
try to use the & operator before the string parameter
like this:
void Frestart (){
by the way, are you trying to make this project as possible?
just change the function to return a string and return the string from the input. much easier.
Lol. Do you build each project over another? Still some of my variables i see
Favourite quotes:
Definition of computing: The use or operation of computers.Code:I don't need easy, I just need possible. ~ Me There are three birds on a fence. Two decide to fly away, how many are left? Three, just because you decide to do something doesn't mean you've done it. ~ Don't know who said this Do not go where the path may lead, go instead where there is no path and leave a trail. ~ Ralph Waldo Emerson
Turning on my computer = computing = programming
LAWLFAIL
my bad, forgot it:
like that
void Frestart (string ITSASTRING, string &restart){
PS. In a production environment, strings are too inefficient in terms of operation speed and memory use. Consider using integers, booleans and other data types that occupy less memory.
PS2. string Var1, Var2, Var3 works as well.
Favourite quotes:
Definition of computing: The use or operation of computers.Code:I don't need easy, I just need possible. ~ Me There are three birds on a fence. Two decide to fly away, how many are left? Three, just because you decide to do something doesn't mean you've done it. ~ Don't know who said this Do not go where the path may lead, go instead where there is no path and leave a trail. ~ Ralph Waldo Emerson
Turning on my computer = computing = programming
LAWLFAIL
Favourite quotes:
Definition of computing: The use or operation of computers.Code:I don't need easy, I just need possible. ~ Me There are three birds on a fence. Two decide to fly away, how many are left? Three, just because you decide to do something doesn't mean you've done it. ~ Don't know who said this Do not go where the path may lead, go instead where there is no path and leave a trail. ~ Ralph Waldo Emerson
Turning on my computer = computing = programming
LAWLFAIL