merging programs

Ok so we have made a test exam program I got that to work. we needed to make a menu driven program got that to work. Now I have to pull it together where if they hit the number one it pulls up the test bank if they hit two its basically the answers. so number 2 or case 2 I had working but when I was trying to integrate my test into case one it doesn't work. I'm just trying to figure out how to make this work I'm sure its all jacked up but if someone can help.

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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
  Pu#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

string & makeLowerCase ( string & String ); //just added
int main()
{
	
	int counter, choice;
	do
	{
		cout << "1) Load an exam" << endl;
		cout << "2) Display an exam" << endl;
		cout << "3) Quit program" << endl;
		cin >> choice;
		switch(choice)
		{
		case 1:
		// begining of new
    string catchGarbage; // This is used to exit.

    string userInput = ""; 

    const int NQS = 4;

    string userAnswers[NQS];
    string quizQuestions[NQS];
    string quizAnswers[NQS];

    // Question 1
    quizQuestions[0] =
            "There is 4 questions total\n"
			"Question 1:\n"
            "TF 25\n\n"
            "There exist birds that cannot fly?\n\n"
            "T\n"
            "F\n";

    quizAnswers[0] = "T";

    // Question 2
    quizQuestions[1] =
            "Question 2:\n"
            "MC 25\n\n"
            "Who was the President of the USA in 1991?\n\n"
            "6\n\n"
            "A Richard Nixon\n"
            "B Gerald Ford\n"
            "C Jimmy Carter\n"
            "D Ronald Reagon\n"
            "E George Bush Sr.\n"
            "F Bill Clinton\n";

    quizAnswers[1] = "E";

    // Question 3
    quizQuestions[2] =
            "Question 3:\n"
            "TF 25\n\n"
            "The city of Boston hosted the 2004 Summer Olympics?\n\n"
            "T\n"
            "F\n";

    quizAnswers[2] = "F";
    
    //just to even out the scoring system i put four
      // Question 4
    quizQuestions[3] =
            "Question 1:\n"
            "TF 25\n\n"
            "There is nine planets?\n\n"
            "T\n"
            "F\n";

    quizAnswers[3] = "T";



    // Other variables
    int a = 0; // set these right away to 0.
    int s = 0;

    cout << "Type 'Start' to begin the quiz, 'Help' for instructions, or 'Exit' to"
            "quit\n" << endl;
    cin >> userInput;
    cout << "\n" << endl;

    if ( makeLowerCase ( userInput ) == "Exit" )
    {
       

        cout << "Thanks for taking the quiz! Press Enter to exit\n";
        //        cin.ignore ( );
        //        cin.get ( );
        getline ( cin, catchGarbage );
       
        //return 0;
       
        // evaluate to true after this.
    }

    if ( makeLowerCase ( userInput ) == "Help" )
    {
        cout << "All questions require a letter as an answer."
                << "For Multiple choice: What color is the sky. A Blue B Green C Red In this"
                " case, you would type 'A' for your chose"
                << "For True or False"
                " You will use a T or F"
                << "Good luck on your quiz\n" << endl;


        cout << "Type 'Start' to begin the quiz or 'Exit' to quit\n" << endl;
        cin >> userInput;
        cout << "\n" << endl;
    }

    if ( makeLowerCase ( userInput ) == "Start" )
    {
        int currentQuestion;

        for ( currentQuestion = 0; currentQuestion < NQS; currentQuestion++ )
        {
            cout << quizQuestions[currentQuestion] << endl;
            cin >> userInput;
            cout << endl << endl;

            // check for "exit" right away.
            if ( makeLowerCase ( userInput ) == "Exit" )
            {
                // now we can check if userInput is == "exit".
                cout << "Thanks for taking the quiz! Press Enter to exit\n";
                getline ( cin, catchGarbage );
                break;
            }

            userAnswers[currentQuestion] = userInput;
            if ( userAnswers[currentQuestion] == quizAnswers[currentQuestion] )
            {
                a++; // you can increment the score like this.
            }
        }

        // If all the questions were successfully asked and answered, display
        // the score. Otherwise, the program exits.
        if ( currentQuestion == NQS )
        {
            s = a * 25;

            if ( s == 100 )
                cout << "Congratulations! You got 100% of the answers right!"
                    "\n" << endl;

            else
                cout << "You answered " << s << "% of questions correct!\n"
                    << endl;
        }
    }

    return 0;
   


		
			break;
			
			
			
			

		case 2:
	cout <<"Question 1\n"
	     <<"True or False worth 25 points\n"
	     <<"There exist birds that cannot fly?\n"
	     <<"Answer is True\n\n";

	cout <<"Question 2\n"
	     <<"Multiple Choice worth 25 points\n"
	     <<"Who was the President of the USA in 1991?\n"
	     <<"Answer is E George Bush Sr. \n\n";

    cout <<"Question 3\n"
         <<"True or False worth 25 points\n"
         <<"The city of Boston hosted the 2004 Summer Olympics?\n"
         <<"Answer is False\n\n";
    
    cout <<"Question 4"       
         <<"True or False worth 25 points\n"  
		 <<"There is nine planets?\n"
         <<"Answer is True\n\n";

			cout << endl;
			break;

// Case 3 ends program if picked
		case 3:
			cout << "Thanks. See you again, later.." << endl << endl;
			return 0;
		default:
			cout << "Options are only choices 1 to 3..  Thank you." << endl;
		} 
	}while (choice >=1 || choice <=3);
 return 0;
 }

string & makeLowerCase ( string & String )
{
   

    for ( int index = 0; index < String.length ( ); index++ )
    {
        tolower ( String[index] );
    }

    // After all the letters are converted, return the modified version.
    return String;
}//end of new
}t the code you need help with here.
 
makeLowerCase ( userInput ) == "Start" 


I don't know what it should be doing, but by the looks of it, you are comparing something lowercase to not lowercase.
I think you should use functions to structure your program. In a structured program you can find problems much easier.
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
int main ()
{
  int counter, choice;
  do
  {
    cout << "1) Load an exam" << endl;
    cout << "2) Display an exam" << endl;
    cout << "3) Quit program" << endl;
    cin >> choice;
    switch (choice)
    {
    case 1:
      LoadExam ();
      break;
    case 2:
      DisplayExam ();
      break;
    case 3:
      cout << "Thanks. See you again, later.." << endl << endl;
      return 0;
    default:
      cout << "Options are only choices 1 to 3..  Thank you." << endl;
    }
  } while (choice >= 1 || choice <= 3);
  
  return 0;
}
Topic archived. No new replies allowed.