Hi again guys! We're almost done with our C++ lesson,through some reading(since the professor is too lazy to teach us!) I've learned some basic parts of C++. Well this week, we'll be passing our project. We are assigned to make a program that will show the use of switches, if statements, loops, functions and array. Well frankly i can't think of a good program so I decided to make an IQ test one.
SO here it goes
- #include <iostream.h>
- #include <conio.h>
- #include <string>
- #include <stdio.h>
- #include <stdlib.h>
- using std::string;
- using namespace std;
- int $gen = 0, $mat = 0, $gKn = 0, $sci = 0;
- int gen[9], mat[9], gKn[9], sci[9];
- char choice;
- string name;
-
-
-
- main()
- {
- int loopcount = 0;
- cout << "Please Enter your First Name:";
- cin >> name;
- system("cls");
- cout << "Welcome " << name <<" to the C++ Pre-IQ test!\nI prepared some"
- << " questions that will test out your knowledge if your capable of doing"
- << " IQ tests! \n\n"
- << "Please select Category\n\n[1]General IQ\n\n[2]Mathematical Abilities"
- << "\n\n[3]General Knowledge\n\n[4]General Science\n\nChoice: ";
- cin >> choice;
- while ($gen == 0 && $mat == 0 && $gKn == 0 && $sci == 0)
- {
- system("cls");
- switch (choice)
- {case '1':
- cout << "General IQ\n"
- << "Please read the question Properly\n\n"
- << "1. What gets wetter and wetter the more it dries \n\n[1] Sand\n[2]"
- << " Face \n[3] Towel \n\n";
- cin >> gen[0];
- if (gen[0] ==3)
- {$gen++;}
- cout << "\nYou answered " <<$gen <<" out of 10 questions!";
- getch();
- system("cls");
- case '2':
- cout << "Mathematical Ability\nPlease read the question Properly\n\n"
- << "1. Which number should come next in this series? \n\t"
- << "25,24,22,19,15 \n[1]4\n[2]5\n[3]10\n\n";
- cin >> mat[0];
- if (mat[0] == 3)
- {$mat++;}
- cout << "\nYou answered " <<$mat <<" out of 10 questions";
- getch();
- system("cls");
- case '3':
- cout << "General Knowledge\n Please read each question Properly\n\n";
- cout << "\n1. Europe is a Country. \n\n[1] Yes\n[2] No\n[3] It is becoming"
- << " somewhat like it.\n\n";
- cin >> gKn[0];
- if (gKn[0] == 2)
- {$gKn++;}
- cout << "\nYou answered " <<$gKn <<" out of 10 questions";
- getch();
- system("cls");
- case '4':
- cout << "Science Test\nPlease read the question Properly\n\n"
- << "\n1. Where in the body are the smallest bones?\n\n[1] Ear\n"
- << "[2] Ankle\n[3] Fingers\n\n";
- cin >> sci[0];
- if (sci[0] == 1)
- {$sci++;}
- cout << "\nYou answered " <<$sci <<" out of 10 questions";
- getch();
- system("cls");
-
- default:
- if(choice >> 4)
- {cout << "Please refer to Choices 1 - 4 only \nThe Program will restart";}
- }
-
- cout << "\ntest loop for scores" << $gen <<$mat <<$gKn << $sci;
- getch();}
-
- getch();
- }
-
-
Well I haven't typed the questions yet since i think it will be quite easy to do that with if statements.
So, my question is, in the default part of my switch, I want to return the program to the "choices" options again instead of closing up. Well im thinking of using a loop there(?) but I dont know how to return it there.
Again, thank you guys!
edit:
And I forgot to thanks Rescudo for helping me out with my last problem.
Yeah! cplusplus.com is a good site.
UPDATEHere's the new code I made.