[split from http://www.daniweb.com/forums/post1162537.html#post1162537]

how can i create like that program but i need to have more questions and i dont nid to use the life time because lifetime is dificult so please help me or give me a program to use in our c++ subject here in MAPUA. please i nid it before this friday, march 19, 2010. please rply asap!!ty so much.. please send it to my email.i just nid a simple program cause i am still a freshmen. [[I]snipped[/I]] this is email.please use if else so that i can defend it and use random for the questions. ty

Dani AI

Generated

asked for a simple, defensible C++ version of "Who Wants to Be a Millionaire" (no lifelines, random question order, use if/else). rightly pointed out that asking others to write and email an assignment is poor practice; a compact, commented skeleton is provided below so the OP can study, modify, and explain each part during a defence. ’s similar request shows this same minimal pattern will meet typical classroom requirements.

The approach: represent each question as a small struct (text, four choices, correct letter), store questions in a container, perform a Fisher–Yates shuffle with rand() to randomize order, present questions one at a time, read a single char answer, and use if/else to check correctness and update score. Reading questions from a text/CSV file lets the dataset grow without changing code.

#include <iostream>
#include <vector>
#include <string>
#include <ctime>
#include <cstdlib>
#include <cctype>

using namespace std;

struct Question {
    string text;
    string opt[4];
    char ans; // 'A'..'D'
};

int main() {
    srand((unsigned)time(NULL));
    vector<Question> qs = {
        {"Capital of France?", {"A) London","B) Paris","C) Rome","D) Madrid"}, 'B'},
        {"2 + 2 = ?", {"A) 3","B) 4","C) 5","D) 6"}, 'B'}
    };

    for (int i = (int)qs.size()-1; i > 0; --i) { // Fisher-Yates
        int j = rand() % (i+1);
        swap(qs[i], qs[j]);
    }

    int score = 0;
    for (size_t i = 0; i < qs.size(); ++i) {
        cout << "Q" << i+1 << ": " << qs[i].text << "\n";
        for (int k = 0; k < 4; ++k) cout << qs[i].opt[k] << "\n";
        cout << "Answer (A-D): ";
        char c; cin >> c; c = toupper(c);
        if (c == qs[i].ans) {
            score += 1000;
            cout << "Correct! Score: " << score << "\n\n";
        } else {
            cout << "Wrong. Correct answer: " << qs[i].ans << "\n";
            break;
        }
    }
    cout << "Final score: " << score << "\n";
    return 0;
}

Notes: seed rand() once; accept lowercase via toupper; expand questions by parsing a CSV (one question, four options, answer per record); if Turbo C++ is mandatory, replace modern STL usage with arrays and legacy headers. For a defendable submission, add comments explaining the shuffle, input validation, and scoring, and show brief test runs.

Recommended Answers

All 2 Replies

1) Speak English. nid? Use sentences. Violation of the Rules.
2) Give you code? Why should we do something you're not willing to do? What's in it for us? Violation of the Rules.
3) ASAP? What makes you so blamed important? All these other member's posts are less important than your program? Why?
4) email? Why should you get special treatment? Violation of the Rules.
5) Special treatment because you're a freshman? No wonder upper classmen dislike freshmen -- they're primadonnas.
6) How can you possibly defend something you didn't write?

hmm.. can you give me the codes for the game/program who wants to be a millionaire ? dis is my final requirment in my subject turboc++ plss help us ?? have mercy? plss..? so dat we can pass and to procede 2ndyr colej plss.? Godbless you all.
dis is my email ad : [email]snipped[/email] plss send it to me as soon as possible deadline is on march 22 thank you !!

commented: Go away you cheating idiot -4
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.