Why does my program keep freezing?

I'm just trying to make a little program to help me study.
I would like to have the program to give me a word and allow me to choose the correct answer in a format of choosing the correct number with its definition.

I have substituted things that I haven't yet learned to do, however, I'm tryiing to make the program as random as possible with choosing each word to ask and giving me a list of four answers to choose from having one with the right answer.

The main reason for this post, however, is that the program keeps freezing before the loop occurs. I think this may be due to my array?

Thanks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <time.h>

using namespace std;
string definitions;
string term;
string vocab();


string termsAndDefinitions [] = {"Acquittal",

"A jury verdict that a criminal defendant is not guilty, or the finding of a judge that the evidence is insufficient to support a conviction.",

"Active judge",

"A judge in the full-time service of the court. Compare to senior judge.",

"Administrative Office of the United States Courts (AO)",

"The federal agency responsible for collecting court statistics, administering the federal courts' budget, and performing many other administrative and programmatic functions, under the direction and supervision of the Judicial Conference of the United States.",

"Admissible",

"A term used to describe evidence that may be considered by a jury or judge in civil and criminal cases.",

"Adversary proceeding",

"A lawsuit arising in or related to a bankruptcy case that begins by filing a complaint with the court, that is, a ""trial"" that takes place within the context of a bankruptcy case.",

"Affidavit",

"A written or printed statement made under oath.",

"Affirmed",

"In the practice of the court of appeals, it means that the court of appeals has concluded that the lower court decision is correct and will stand as rendered by the lower court.",

"Alternate juror",

"A juror selected in the same manner as a regular juror who hears all the evidence but does not help decide the case unless called on to replace a regular juror.",

"Alternative dispute resolution (ADR)",

"A procedure for settling a dispute outside the courtroom. Most forms of ADR are not binding, and involve referral of the case to a neutral party such as an arbitrator or mediator.",};

string wordGenerator();
string multipleChoice();
int main()
{
    int a = 1, b = 2;
    cout << "Welcome to Terms and Definitions of Legal Terms" << endl << endl;
while (b>a) {
        cout << "Welcome to Terms and Definitions of Legal Terms" << endl << endl;
    wordGenerator();
  }



    /////////////////////////////////////////////////////////////////////////////////////////////


    return 0;
}
string wordGenerator()
{

    string multipleAnswers[2];

    int number = 0;
    cout << "What is " <<termsAndDefinitions[number] << "?" << endl << endl;
    multipleChoice();
    //cout << "Choose one of the following: " << endl << endl <<"(1)" << termsAndDefinitions[number + 1] << endl << endl << " OR " << endl << endl << "(2) " << termsAndDefinitions[number + 3] << "?" << endl << endl;
    //cout << "It is" <<termsAndDefinitions[number++];
    //cout << "What is " <<termsAndDefinitions[rand() % 8] << "?";




}
string multipleChoice()
    {
        string answer = "hi";
        int number = 0;
        loop:
        //multipleAnswers[termsAndDefinitions[number], termsAndDefinitions[number + 1], termsAndDefinitions[number + 3]];
        cout << "Choose one of the following: " << endl << endl <<"(1)" << termsAndDefinitions[number + 1] << endl << endl << " OR " << endl << endl << "(2) " << termsAndDefinitions[number + 3] << "?" << endl << endl;
        getline(cin, answer);
        if (answer == "1")
            cout << "Good job";


        else
        {cout << "Try again";
                goto loop; }

    }
Compile with warnings
In function ‘std::string wordGenerator()’:
44:9: warning: unused variable ‘multipleAnswers’ [-Wunused-variable]
51:1: warning: no return statement in function returning non-void [-Wreturn-type]
In function ‘std::string multipleChoice()’:
66:1: warning: no return statement in function returning non-void [-Wreturn-type]
For one, your functions multipleChoice and wordGenerator return something of type string, but here don't return anything. Also, you never use multipleAnswers. Also, you included ctime, which would allow for the randomness you require (if need-be, I'll give you my itty-bitty function for a random number). As for your array of strings, it would be easier to confine its size to a SIZE constant which is just however many strings are in your array. That way, when picking a random number, you're already given one over the highest number you can put into the array as to obtain a value.

What I would recommend is to make two arrays. Have one to be for the terms, and the other for definitions. Pick a random number for the definition, and then pick 3 random numbers for the answers, where the fourth is correct. The actual ordering of this is also calculated with random numbers.
Last edited on
Topic archived. No new replies allowed.