/* Victor Chen 11-2-09 COP 3223 Section 3 Creates a game from a choice of 3: addition, multiplication, factoring and calculates a score based on time spent on the problems and whether the user got the question right or wrong */ #include #include #include #define ADD 1 #define MULT 2 // enabling functions to be called double arithGame(int max, int quantity, int op); double factorGame(int max, int quantity); int numPoints(double timesec); int menu(); int main(){ int choice, ans; int e,f,g; int x, y; int points = 0; srand(time(0)); //prints menu ans = menu(); // loops for the correct choice while(ans!=4){ // if user selects Arithmetic if(ans == 1){ printf("Would you like, 1)Addition or 2)Multiplication?\n"); scanf("%d", &g); printf("What is the maximum number you would like?\n"); scanf("%d", &e); printf("How many problems do you want?\n"); scanf("%d", &f); int start = time(0); points= points+arithGame(e,f,g); // returns arithmetic game and calculates points } // if user selects to do Factorial game if(ans == 2){ printf("Enter the maximum value of a factor.\n"); scanf("%d", &x); printf("How many factoring problems do you want?\n"); scanf("%d", &y); points = points+factorGame(x,y); // returns factorial game and calculates points } // if user requests score if(ans == 3){ printf("Your score is %d.\n", points); } ans = menu(); } printf("Thank you for playing!\n"); system("PAUSE"); return 0; } // Precondition: none //Postcondition: Prints out the menu int menu(){ int num = 0; while (num!=1 && num!= 2 && num!=3 && num!=4){ printf("Please make a selection from the following:\n"); printf("1. Play Arithmetic Game.\n"); printf("2. Play Factoring Game.\n"); printf("3. Print Score.\n"); printf("4. Quit.\n"); scanf("%d", &num); if (num!=1 && num!=2 && num!=3 && num!=4) printf("Sorry, your choice is invalid, try again.\n"); } return num; } //Precondition: User enters 1 //Postcondition: double arithGame(int max, int quantity, int op) { int index, value1, value2, response; int penalty = 0, score = 0; int start = time(0); // If user choosea Arithmetic Addition if(op==ADD) { for (index = 0; index= 1)&&(timesec<2)) return 9; else if((timesec>=2) && (timesec<3)) return 8; else if((timesec>=3) && (timesec<4)) return 7; else if((timesec>=4) && (timesec<5)) return 6; else if((timesec>=5) && (timesec<6)) return 5; else if((timesec>=6) && (timesec<7)) return 4; else if ((timesec>=7) && (timesec<8)) return 3; else if((timesec>=8) && (timesec<9)) return 2; else if((timesec>=9) && (timesec<10)) return 1; else if(timesec>=10) return 0; }