//This is Practice Program I am making
#include <iostream> // Include the standard
#include <windows.h> // We need to include this for "console" functions.
#include <string> // Allows us to use the "string" type
using namespace std; // Use the standard namespace (blah blah, not important to understand right now)
string userName; //The variable for there name
int Age; //The variable for there age
int Play; //the variable to determine if they want to play or not
int Answer; //variable for answers with numbers
int score = 0; //variable that keeps track of there score
int total = 0; //variable that keeps track of there number of questions
// Here is our function that draw's a color string in a DOS window.
// We just pass in the string, the X and Y position, then the color we desire.
// The color can be a background color AND a foreground color. Here are some color examples:
// FOREGROUND_GREEN; FOREGROUND_RED; FOREGROUND_BLUE; - BACKGROUND_RED; BACKGROUND_BLUE; BACKGROUND_GREEN;
// You can mix and match these to create other colors. Look in "Main()" to see how
void DrawColorString(string szText, int X, int Y, WORD color)
{
HANDLE OutputH; // This will be used for our handle to the output (basically, holds permission to change the output settings)
COORD position = {X, Y}; // Create a COORD and set it's x and y to the X and Y passed in.
OutputH = GetStdHandle(STD_OUTPUT_HANDLE); // Get a OUTPUT handle to our screen.
SetConsoleTextAttribute(OutputH, color); // Set the text attribute to what ever color that was passed in.
// The function SetConsoleTextAttribute takes (the handle to the output, and the color);
SetConsoleCursorPosition(OutputH, position); // Set the cursor position to the desire position passed in.
cout << szText; // Now print out what we wanted to at the position that was passed in.
}
int Trivia()
{
cout << "\t\tWould you like to play my computer trivia game?\n\t\tPlease Enter 1 for yes, 2 for no!\t";
cin >> Play; //requires user input, 1 for yes, 2 for no.
if(Play==1) //This starts up trivia
{
cout << "\n\n\n\t\tWelcome to Computer Trivia!\n\t\tPrepare for your First Question.\n";
cout << "\n\n\n\n\n\n\n\t\tQuestion 1:\n\t\tHow many bytes are in a Kilobyte?\n";
cout << "\t\tPlease type your answer here.\t";
total = total + 1;
cin >> Answer;
if(Answer==1024)
{
cout << "\n\tThat is a correct answer, your doing good, keep up the good work!\n";
cout << "\t\tLet's move onto the next question!\n";
score = score + 1;
}
else
{
cout << "\n\t\t\tSorry, that's the wrong answer.\n";
cout << "\tThe correct answer is that there is 1024 bytes in a kilobyte\n";
}
cout << "\n\n\n\n\n\n\t\tQuestion 2:\n\tWhat did you enter your age as at the beginning of this program?\n";
cout << "\t\t\t\t";
total = total + 1;
cin >> Answer;
if (Answer==Age)
{
cout << "\n\tAwesome, that's a correct answer, you got good memory!\n";
cout << "\t\tOn with the next question as they say\n";
score = score + 1;
}
else
{
cout << "\n\t\t\tSorry, that's the wrong answer.\n";
cout << "\tYou entered your age as "<< Age << " at the beginning of the game\n";
}
cout << "\n\n\n\n\n\n\t\tQuestion 3:\n\t";
cout << "\tWhat is the decimal for binary 110101\t";
total = total + 1;
cin >> Answer;
if (Answer==47)
{
cout << "\n\t\tWow, trick questions dont fool you, do they\n";
score = score + 1;
}
else
{
cout << "\n\t\t\tSorry, that's the wrong answer.\n";
cout << "\t\tThe correct answer is 47!\n";
}
cout << "\n\n\n\n\n\n\t\tQuestion 4:\n\t";
cout << "\tWhat does RAM stand for\n";
cout << "\t\tPlease enter the number of the multi-choice\n";
cout << "\n\t\t1) Real Access Memory";
cout << "\n\t\t2) Random Area Message";
cout << "\n\t\t3) Random Access Memory";
cout << "\n\t\t4) Radio Active Machine\t\t";
total = total + 1;
cin >> Answer;
if (Answer==3)
{
cout << "\n\t\tExcellent, you got the first multi-choice right";
score = score + 1;
}
else
{
cout << "\n\t\t\tSorry, that's the wrong answer.\n";
cout << "\t\tThe correct answer is 3)Random Access Memory.";
}
cout << "\n\n\n\n\n\n\t\tYour score was " << score << "/" << total << "\n";
}
else if(Play==2) //This is if they dont want to play and it quits
{
cout << "\n\n\t\tYou dont want to play my Trivia Game!\n";
cout << "\t\tWell I am sorry about that.\n\t\tYour lost, HAHAHA\n";
return 0;
}
else //This is if they don't enter yes or no
{
cout << "\t\tI'm sorry but that wasn't a valid entry.\n";
cout << "\t\tPlease try again\n";
Trivia();
}
return 0;
}
int main()
{
DrawColorString("\t\t Welcome to my Practice Program!", 0, 0, FOREGROUND_RED);
cout << endl << endl <<"\t\tHi my name is Falto the Computer Program.\n"; // The welcome message to my program
cout << "\t\t\tWhat is your name?\n\t\t\t "; //asks them what there name is
cin >> userName; //requires user input, up to 20 characters long
cout << "\n\n\t\tWelcome " << userName << " to my practice program!\n"; //Displays there name and says message
cout << "\t\tI was born on September 14 2002\n\t\tSo that means you can calculate my age.\n\t\tWhat is your age?\t";
cin >> Age; //requires user input for there age
cout << "\n\t\tYou are " << Age << " years old, and your name is " << userName << ".\n";
Trivia();
return 0; //returns the value of zero to your program
}
Colored Text Problem
I am having a problem when i color text, it starts working out just find, then after about 3 paragraphs and like 2 cin's the color goes all screwy and some letters are colored and the others are gray. Does anyone know how to fix this problem. I'll paste my code here for you people to look at. Thanx again for taking your time to help.
That is all of my code!
~~SURG~~
[edited by - Surg AKA Kunark on September 20, 2002 11:55:40 PM]
~~Johnathan~~LTM my new fad, know it, use it, love it, LAUGHING TO MYSELF
didn''t you have a post up this morning around 2 or 4 am??
did the moderator delete it??
did the moderator delete it??
Well, where you live it might have been in the moring, yes i did, I screwed up when i went to modify it. But all the stuff you told me worked. I loved the help, if you notice in my code there is no goto statements anymore, i made trivia into a function and went to that tutorial site and downloaded them all and have gone through like the first 20 of them. You see, when you babysit you have lots of time to work on the computer, lol. It's 10:00 at night over here right now.
I have also used the string stuff to check on someone's userName and if they enter the wrong username they get the answer incorrect. I have to have some easy questions, lol, since almost my whole family is computer illiterate --mind my spelling -- .
~~Surg~~
[edited by - Surg AKA Kunark on September 20, 2002 12:16:23 AM]
I have also used the string stuff to check on someone's userName and if they enter the wrong username they get the answer incorrect. I have to have some easy questions, lol, since almost my whole family is computer illiterate --mind my spelling -- .
~~Surg~~
[edited by - Surg AKA Kunark on September 20, 2002 12:16:23 AM]
~~Johnathan~~LTM my new fad, know it, use it, love it, LAUGHING TO MYSELF
I still need help, please and thank you.
~~BUMP~~ stole your saying hahahaha
~~SURG~~
LTM my new fad, know it, use it, love it, LAUGHING TO MYSELF
~~BUMP~~ stole your saying hahahaha
~~SURG~~
LTM my new fad, know it, use it, love it, LAUGHING TO MYSELF
~~Johnathan~~LTM my new fad, know it, use it, love it, LAUGHING TO MYSELF
I still havn''t firgured out how to fix this, does aynone know.
~~Johnathan~~LTM my new fad, know it, use it, love it, LAUGHING TO MYSELF
Well, I have solved the problem, its just my computer there is nothing wrong in the actual coding. Others have looked and it works properly so tomorrow i shall be deleting this message. Thanx all for the help.
~~Johnathan~~LTM my new fad, know it, use it, love it, LAUGHING TO MYSELF
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement