can u please help me?
this was my teacher's project for us!
i really dont know what to do!

Dani AI

Generated

wanted a C++ program that asks five questions and requires answers. provided a tiny skeleton; the material below expands that into a complete, minimal console quiz and explains the key points so the assignment can be implemented reliably.

Design notes: keep question/answer pairs in a small container, present each question, and loop until a non-empty answer is given so skipping is impossible. Use std::getline (not operator>>) so answers with spaces work; trim whitespace before checking emptiness. For comparison, convert both the entered answer and the stored correct answer to lower case to avoid case mismatches. If the teacher expects single-letter choices (A/B/C) or numeric answers, replace the free-text acceptance with a short validation loop that only accepts allowed characters. Common pitfalls include leftover newlines when mixing >> and getline, and failing to trim leading/trailing spaces before comparing.

A compact example follows; it enforces an answer for each question and prints a final score.

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cctype>

struct QA { std::string q; std::string a; };

static std::string trim(const std::string &s) {
    size_t start = s.find_first_not_of(" \t\r\n");
    if (start == std::string::npos) return "";
    size_t end = s.find_last_not_of(" \t\r\n");
    return s.substr(start, end - start + 1);
}

static std::string lower(const std::string &s) {
    std::string r(s);
    std::transform(r.begin(), r.end(), r.begin(),
                   [](unsigned char c){ return std::tolower(c); });
    return r;
}

int main() {
    std::vector<QA> quiz = {
        {"What is the capital of France?", "Paris"},
        {"How many months have 31 days?", "7"},
        {"What language is this program written in?", "C++"},
        {"What color results from mixing red and white?", "Pink"},
        {"2 + 3 = ?", "5"}
    };

    int score = 0;
    for (size_t i = 0; i < quiz.size(); ++i) {
        std::string answer;
        do {
            std::cout << "Q" << (i+1) << ": " << quiz[i].q << "\nAnswer: ";
            if (!std::getline(std::cin, answer)) return 0;
            answer = trim(answer);
        } while (answer.empty());

        if (lower(answer) == lower(quiz[i].a)) ++score;
    }

    std::cout << "Final score: " << score << " / " << quiz.size() << "\n";
    return 0;
}

Note: this is a console example; adapt to file I/O or stricter option validation if the assignment requires different input/output or persistence.

Recommended Answers

All 3 Replies

I think it's fairly obvious...

You'll need output, input, and comparison statements. Hmmmm...., you'll probably need some loops and a return statement as well.

.can i have the code pls?
for me to start this program...,")

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.