My first C++ Program (Sorry for stealing the thread... But here's MY :) )
#include <iostream.h>
using namespace::std;
int main() { char name[32]; char hobby[32]; char question1[15]; char question2[15]; char question3[15]; int alder;
cout <<"Hello and welcome to my storytelling game.\nPlease enter the information as it's told to." << endl; cout <<"Press [ENTER] to Continue\n"; cin.get(); cout <<"First of all, What is your name?" << endl; cin >> name; cout <<"Second of all, how old are you?" << endl; cin >> alder;
if (alder <= 16) { cout <<"Ok, you're a bit young but it's OK :)"<< endl; } else if (alder >= 16) { cout <<"Great, then you can continue without getting insulted." << endl; }
cout <<"Well, let's continue… What is your main hobby?\n"; cin >> hobby;
if (strcmp(hobby, "Computers") == 0) { cout <<"Couldn't you picked anything else than computers? Geek…\n" ; } else { cout <<"Ok, so your favorite hobby is " << hobby << " :). That's nice!\n "; }
cout <<"That's all the info about YOU i need. Now you have to answer some of my questions.\n If you don't know the correct answer. You're doomed! \n"; cout <<"Ok, when you're ready for your first question, press [ENTER] to proceed!\n"; cin.get(); cout <<"Alright. What's the name of the programming language this program is written in ?\n";
cout <<" Programcode:" ; cin >> question1;
if (strcmp(question1, "C++") == 0) { cout <<"Great, now you can continue with the second question. Press [ENTER] to proceed.\n"; cin.get(); cout <<"Ok, now for question two. What is the most common language used for medium quality games, mobile applications and web plugins?\n"; cout <<"(You can't lose on this one: "; cin >> question2;
if (strcmp(question2, "Java") == 0)
{
cout <<"BINGO! Now there's just one more question for you to do, then you're ready to go!\n";
cout <<"Press [ENTER] to proceed.\n";
cin.get();
cout <<"Ok, seems like you've been waiting so long to get this crappy C++ game finished.\n So now i'm gonna give you, the last, and final question." << endl;
cout <<"When you're ready, press [ENTER].\n";
cin.get();
cout <<"Here it goes:\n How many full albums has Enter Shikari released? \n";
cout <<"(HAAHAHA, Didn't see that coming, ey? PS. Write in letters not in numbers.)";
cin >> question3;
if (strcmp(question3, "One") == 0)
{
cout <<"Congratulations! You're the winner of my crappy C++ game.\n You can now call yourself a proud owner of a netpotato!";
cin.get();
}
else
{
cout <<"Aaw =/ You were SOOO close. If you wanna play again just restart the application \n because i dont really know yet how to restart things in C++ :(";
cin.get();
}
}
else
{
cout <<"NO! You were so close... But hey, this is only gonna bring you:" << endl;
cout <<"ZE DOOOOOOOM! \n";
cout <<"ZE DOOOOOOOM! \n";
cout <<"ZE DOOOOOOOM! \n";
cout <<"ZE DOOOOOOOM! \n";
cout <<"ZE DOOOOOOOM! \n";
cout <<"ZE DOOOOOOOM! \n";
}
} else { cout <<"Oops :( Man it's not that hard. It's C++! \n"; cout <<"Sorry man, but now you're doomed. Byebye!"; }
cin.get();
return 0;
}
*UPDATED THE CODE A BIT! :) *
What do you think about that? It's like UBER basic. And i can't even get it to run because it gets some few errors :/
Anyone know what it is? And anyone can give me some critisism for the sake that i've been studying C++ in like… 4 hours (2 days, 1-2 hours /day).
Thanks :)
I saw how u didnt know how to restart the program. since you a beginner try using a goto command(its not restrting a program but it can travel you back to later block of code or forward to a newer block. TO those who know how to code i relize the Goto command is obsalete but the fact is its still a very simple way to go back or forward in code
i dont quite remeber C++ anymore i prefer VB.NET but it might be
CRAZY:
Code here
goto CRAZY
SwartMumba wrote: One more thing, shouldn't your one line of code be:
using namespace std;
Ye, maybe :/ Well, i'll correct that!:)
SET wrote: I saw how u didnt know how to restart the program. since you a beginner try using a goto command(its not restrting a program but it can travel you back to later block of code or forward to a newer block. TO those who know how to code i relize the Goto command is obsalete but the fact is its still a very simple way to go back or forward in code
i dont quite remeber C++ anymore i prefer VB.NET but it might be
CRAZY:
Code here
goto CRAZY
Ok, thx! :)
Also, for string inputs, you should use getline(cin, variablename);
Like for your name input, if someone types their full name instead of just their first name (you don't specify what to do exactly) it'll just read the first name and ignore the last name because of the space between them. getline() will read the full string. :)
Skunkfoot wrote: Also, for string inputs, you should use getline(cin, variablename);
Like for your name input, if someone types their full name instead of just their first name (you don't specify what to do exactly) it'll just read the first name and ignore the last name because of the space between them. getline() will read the full string. :)
So instead of writing :
cin >> variablename;
i should write:
getline(cin, variablename); ? :) But should i output it the same way? With the if (strcmp(varname, "string") == 0) ?
Or am i totally lost ? xD
Grinziel wrote:
So instead of writing :
cin >> variablename;
i should write:
getline(cin, variablename); ? :) But should i output it the same way? With the if (strcmp(varname, "string") == 0) ?
Or am i totally lost ? xD
that's right. the point is that if you try to do a cin, it will only take input up until it finds a space (so if someone entered "john smith" as their name, it would only store "john" into the variable). a getline will take in the entire line.
ynori7 wrote: [quote]Grinziel wrote:
So instead of writing :
cin >> variablename;
i should write:
getline(cin, variablename); ? :) But should i output it the same way? With the if (strcmp(varname, "string") == 0) ?
Or am i totally lost ? xD
that's right. the point is that if you try to do a cin, it will only take input up until it finds a space (so if someone entered "john smith" as their name, it would only store "john" into the variable). a getline will take in the entire line.[/quote]
ok, thx :D That actually helped me a lot :) Right now i'm on a lowclass project who should be similiar to the game Mastermind. It's hard, and now i'm stuck, but i'll guess it'll turn out in some way when i have more experience in C++ :)
Wish me GL :)
Regards, Grinziel.
But, with your updated code, the program still doesn't run.. I've tried to compile it myself, here's what I've ran into:
markupif (strcmp(hobby, "Computers";) == 0)
Why is there a ';' within the strcmp function? You should put a ';' at the end of a full sentence of C++, but not at the end of the variables in a function.
The new code:
using namespace::std;
int main()
{
char name[32];
char hobby[32];
char question1[15];
char question2[15];
char question3[15];
int alder;
cout <<"Hello and welcome to my storytelling game.\nPlease enter the information as it's told to." << endl;
cout <<"Press [ENTER] to Continue\n";
cin.get();
cout <<"First of all, What is your name?" << endl;
cin >> name;
cout <<"Second of all, how old are you?" << endl;
cin >> alder;
if (alder <= 16)
{
cout <<"Ok, you're a bit young but it's OK :)"<< endl;
}
else if (alder >= 16)
{
cout <<"Great, then you can continue without getting insulted." << endl;
}
cout <<"Well, let's continue... What is your main hobby?\n";
cin >> hobby;
if (strcmp(hobby, "Computers") == 0)
{
cout <<"Couldn't you picked anything else than computers? Geek...\n" ;
}
else
{
cout <<"Ok, so your favorite hobby is " << hobby << ":) . That's nice!\n ";
}
cout <<"That's all the info about YOU i need. Now you have to answer some of my questions.\n If you don't know the correct answer. You're doomed! \n";
cout <<"Ok, when you're ready for your first question, press [ENTER] to proceed!\n";
cin.get();
cout <<"Alright. What's the name of the programming language this program is written in ?\n";
cout <<" Programcode:" ;
cin >> question1;
if (strcmp(question1, "C++") == 0)
{
cout <<"Great, now you can continue with the second question. Press [ENTER] to proceed.\n";
cin.get();
cout <<"Ok, now for question two. What is the most common language used for medium quality games, mobile applications and web plugins?\n";
cout <<"(You can't lose on this one: ";
cin >> question2;
if (strcmp(question2, "Java") == 0)
{
cout <<"BINGO! Now there's just one more question for you to do, then you're ready to go!\n";
cout <<"Press [ENTER] to proceed.\n";
cin.get();
cout <<"Ok, seems like you've been waiting so long to get this crappy C++ game finished.\n So now i'm gonna give you, the last, and final question." << endl;
cout <<"When you're ready, press [ENTER].\n";
cin.get();
cout <<"Here it goes:\n How many full albums has Enter Shikari released? \n";
cout <<"(HAAHAHA, Didn't see that coming, ey? PS. Write in letters not in numbers.)";
cin >> question3;
if (strcmp(question3, "One") == 0)
{
cout <<"Congratulations! You're the winner of my crappy C++ game.\n You can now call yourself a proud owner of a netpotato!";
cin.get();
}
else
{
cout <<"Aaw =/ You were SOOO close. If you wanna play again just restart the application \n because i dont really know yet how to restart things in C++ ";
cin.get();
}
}
else
{
cout <<"NO! You were so close... But hey, this is only gonna bring you:" << endl;
cout <<"ZE DOOOOOOOM! \n";
cout <<"ZE DOOOOOOOM! \n";
cout <<"ZE DOOOOOOOM! \n";
cout <<"ZE DOOOOOOOM! \n";
cout <<"ZE DOOOOOOOM! \n";
cout <<"ZE DOOOOOOOM! \n";
}
}
else
{
cout <<"Oops Man :( it's not that hard. It's C++! \n";
cout <<"Sorry man, but now you're doomed. Byebye!";
}
cin.get();
return 0;
}
Happy coding ;) -Tov-
-Tov- wrote: But, with your updated code, the program still doesn't run.. I've tried to compile it myself, here's what I've ran into:
markupif (strcmp(hobby, "Computers";) == 0)
Why is there a ';' within the strcmp function? You should put a ';' at the end of a full sentence of C++, but not at the end of the variables in a function.
The new code:
using namespace::std;
int main()
{
char name[32];
char hobby[32];
char question1[15];
char question2[15];
char question3[15];
int alder;
cout <<"Hello and welcome to my storytelling game.\nPlease enter the information as it's told to." << endl;
cout <<"Press [ENTER] to Continue\n";
cin.get();
cout <<"First of all, What is your name?" << endl;
cin >> name;
cout <<"Second of all, how old are you?" << endl;
cin >> alder;
if (alder <= 16)
{
cout <<"Ok, you're a bit young but it's OK :)"<< endl;
}
else if (alder >= 16)
{
cout <<"Great, then you can continue without getting insulted." << endl;
}
cout <<"Well, let's continue... What is your main hobby?\n";
cin >> hobby;
if (strcmp(hobby, "Computers") == 0)
{
cout <<"Couldn't you picked anything else than computers? Geek...\n" ;
}
else
{
cout <<"Ok, so your favorite hobby is " << hobby << ":) . That's nice!\n ";
}
cout <<"That's all the info about YOU i need. Now you have to answer some of my questions.\n If you don't know the correct answer. You're doomed! \n";
cout <<"Ok, when you're ready for your first question, press [ENTER] to proceed!\n";
cin.get();
cout <<"Alright. What's the name of the programming language this program is written in ?\n";
cout <<" Programcode:" ;
cin >> question1;
if (strcmp(question1, "C++") == 0)
{
cout <<"Great, now you can continue with the second question. Press [ENTER] to proceed.\n";
cin.get();
cout <<"Ok, now for question two. What is the most common language used for medium quality games, mobile applications and web plugins?\n";
cout <<"(You can't lose on this one: ";
cin >> question2;
if (strcmp(question2, "Java") == 0)
{
cout <<"BINGO! Now there's just one more question for you to do, then you're ready to go!\n";
cout <<"Press [ENTER] to proceed.\n";
cin.get();
cout <<"Ok, seems like you've been waiting so long to get this crappy C++ game finished.\n So now i'm gonna give you, the last, and final question." << endl;
cout <<"When you're ready, press [ENTER].\n";
cin.get();
cout <<"Here it goes:\n How many full albums has Enter Shikari released? \n";
cout <<"(HAAHAHA, Didn't see that coming, ey? PS. Write in letters not in numbers.)";
cin >> question3;
if (strcmp(question3, "One") == 0)
{
cout <<"Congratulations! You're the winner of my crappy C++ game.\n You can now call yourself a proud owner of a netpotato!";
cin.get();
}
else
{
cout <<"Aaw =/ You were SOOO close. If you wanna play again just restart the application \n because i dont really know yet how to restart things in C++ ";
cin.get();
}
}
else
{
cout <<"NO! You were so close... But hey, this is only gonna bring you:" << endl;
cout <<"ZE DOOOOOOOM! \n";
cout <<"ZE DOOOOOOOM! \n";
cout <<"ZE DOOOOOOOM! \n";
cout <<"ZE DOOOOOOOM! \n";
cout <<"ZE DOOOOOOOM! \n";
cout <<"ZE DOOOOOOOM! \n";
}
}
else
{
cout <<"Oops Man :( it's not that hard. It's C++! \n";
cout <<"Sorry man, but now you're doomed. Byebye!";
}
cin.get();
return 0;
}
Happy coding ;) -Tov-
Oh, that was accidental :/ Thx anyways :D