lundi 6 août 2018

How do I make my quiz code more efficient?

I made this not knowing where to start so forgive me for anything unnecessary. The idea is to take inputs, store them in arrays, and calculate the percentage of correct answers. I'm not sure if there is a better or shorter way. Are arrays appropriate or no? Anyways, here is the code.

#include <iostream>
#include <stdlib.h>

using namespace std;

int main()
{
    float n = 0;
    const char a = 'a';
    const char b = 'b';
    char foo[10];

    cout << "What is the capital of Missouri?\n\na. Jefferson City \nb. Langsing \nc. Concord \nd. Boston \n" << endl;
    cout << "Type a, b, c, or d: ";
    cin >> foo[0];
    system("CLS");

    cout << "What is the population of Texas?\n\na. 39,536,653 \nb. 28,304,596 \nc. 10,429,379 \nd. 3,930,864\n" << endl;
    cout << "Type a, b, c, or d: ";
    cin >> foo[1];
    system("CLS");
    if (foo[0] == a)
    n = n + 1;
    if (foo[1] == b)
    n = n + 1;

    n = n/2 *100;
    cout << "You made a " << n << " on your test!" << endl;
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire