Welcome
Welcome to the forums of AntiRTFM's Absolute N00b Spoonfeed C++ Tutorials!

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. Registration is fast, simple, and absolutely free, so please, <a href="/profile.php?mode=register">join our community today</a>!

Simple Quiz Game

Finished making your own program (thats not part of the practicing forums) ? Show it off here

Simple Quiz Game

Postby SurowiTheKiller on Sat Oct 10, 2009 5:39 pm

I've been working in C++ , and after learning from antiRTFM tutorials and other sources i made this.Simple Quiz Game , and here is the code .If there is another better way to do it please reply here!The compiler i'm using is Dev C++ . Sorry if the code isn't very organized,because i don't put a lot of spaces.
Code: Select all
#include <iostream>
#include <string>
using namespace std;
void secondq();
void thirdq();
void fourthq();
void fifthq();
int main()
{
    string answer;
    cout<<"In this quiz there will be 5 questions.\n";
    cout<<"Answer with lower case letters.\n\n\n";
    cout<<"1.What is the name of company that made Windows?\n";
    cin>>answer;
    if (answer == "microsoft")
    {
       cout<<"That is correct!\n\n";
       secondq();
    }
    else
    {
        cout<<"That is incorrect!\n\n";
        secondq();
    }
    system("pause");
    return 0;
}
void secondq()
{
    string answer;
    cout<<"2.Is C++ a dog?(Answer with Yes or No.)\n";
    cin>>answer;
    if (answer == "no")
    {
       cout<<"That is correct!\n\n";
       thirdq();
       
    }
    else
    {
        cout<<"That is incorrect!\n\n";
        thirdq();
    }
}
void thirdq()
{
    string answer;
    cout<<"3.What age do we call when it snows?\n";
    cin>>answer;
    if (answer == "winter")
    {
       cout<<"That is correct!\n\n";
       fourthq();
       
    }
    else
    {
        cout<<"That is incorrect!\n\n";
         fourthq();
    }
}
void fourthq()
{
    string answer;
    cout<<"4.What is the thing where we swim and play?\n";
    cin>>answer;
    if (answer == "pool")
    {
       cout<<"That is correct!\n\n";
        fifthq();
       
    }
    else
    {
        cout<<"That is incorrect!\n\n";
        fifthq();
    }
}
void fifthq()
{
    string answer;
    cout<<"Here is the last question.\n\n";
    cout<<"5.What is the name of famous website for sharing and uploading videos?\n";
    cin>>answer;
    if (answer == "youtube")
    {
       cout<<"That is correct!\n\n\n";
       cout<<"Thank you for playing!\n";
       
    }
    else
    {
        cout<<"That is incorrect!\n\n\n";
        cout<<"Thank you for playing!\n";
    }
}
SurowiTheKiller
 
Posts: 29
Joined: Sat Oct 10, 2009 5:09 pm
Location: windows/system32

Re: Simple Quiz Game

Postby glinka57 on Sat Oct 10, 2009 10:45 pm

LOL neat. hey you mean "what is the 'season' when it snows. you said age. lol
fun, make more questions, and maybe a score thing
User avatar
glinka57
 
Posts: 195
Joined: Fri Feb 27, 2009 7:32 pm

Re: Simple Quiz Game

Postby Vevix on Sun Oct 11, 2009 12:08 am

There is a couple ways you can improve the code.

You don't need to enforce the use of lowercase answers on the user - Why not grab whatever they enter and transform it to a lowercase string

an example of this would be:
Code: Select all
std::transform(answer.begin(), answer.end(), answer.begin(), tolower);

Called after you have retrieved the users input


---------------------------


Code: Select all
std::cin >> answer;


This will only pick up one word, It's probably better to use something like this in the future just in case:

Code: Select all
getline(std::cin, answer);



---------------------------


Code: Select all
if (answer == "microsoft")


Use methods provided to you by the string class:

Code: Select all
if (answer.compare("microsoft") == 0) // a return of 0 means the two strings match



---------------------------


Are all the functions really necessary? The program is only small, you may as well do it in main()

I'm sorry if I was too picky :P, It's a good job for someone who is learning the language - If you need something more explained I'll be more than happy.
C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg. -- Bjarne Stroustrup
User avatar
Vevix
 
Posts: 142
Joined: Sat Oct 10, 2009 9:24 pm
Location: kernel32.dll

Re: Simple Quiz Game

Postby SurowiTheKiller on Sun Oct 11, 2009 10:04 am

glinka57 wrote:LOL neat. hey you mean "what is the 'season' when it snows. you said age. lol
fun, make more questions, and maybe a score thing


I put age instead of season because i m Serbia , and my english isnt very well.

Vevix thanks for the update.
SurowiTheKiller
 
Posts: 29
Joined: Sat Oct 10, 2009 5:09 pm
Location: windows/system32

Re: Simple Quiz Game

Postby DevGeek++ on Sun Oct 11, 2009 11:49 am

Oooo dobro dosao prijatele,mi smo komsii,ja sam juzno od tebe :)

P.S: Sorry for my non-english text :)
DevGeek++
 
Posts: 28
Joined: Tue Aug 04, 2009 5:54 am

Re: Simple Quiz Game

Postby SurowiTheKiller on Thu Oct 15, 2009 11:42 am

makedonac :D , jel ima josh komsija ovde?
SurowiTheKiller
 
Posts: 29
Joined: Sat Oct 10, 2009 5:09 pm
Location: windows/system32


Return to Full programs

Who is online

Users browsing this forum: No registered users and 0 guests