Advertisement
nosyrbllewe

States vs. Cities Quiz

Feb 11th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.94 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. const int citiesCount = 35;
  6. const int stateCount = 50;
  7. const int totalQuestions = 5;
  8. const int passingScore = 3;
  9.  
  10. int questionsCorrect = 0;
  11.  
  12. const char cities[][50] = {
  13.     "Chicago","Los Angeles", "San Francisco", "Orlando", "Seattle",
  14.     "Boston", "Atlanta", "Richmond", "Charleston", "Nashville",
  15.     "Austin", "Houston", "Las Vegas", "Phoenix", "Detroit",
  16.     "Flint", "Portland", "San Deigo", "Philadelphia", "Miami",
  17.     "Tampa", "New Orleans", "Honolulu", "Redmond", "Pittsburgh",
  18.     "Cleveland", "Indianapolis", "Baltimore", "Tallahassee", "Denver",
  19.     "St. Paul", "Helena", "Boise", "Albuquerque", "Santa Fe",
  20.     "Lincoln", "Dallas", "Frankfort", "Chenyenne", "Bismark",
  21.     "Columbus", "Albany", "Charlotte", "Birmingham", "Memphis",};
  22.  
  23. const char states[50][50] = {
  24.     "Alabama","Alaska", "Arizona", "Arkansas", "California",
  25.     "Colorado", "Connecticut", "Deleware", "Florida", "Georgia",
  26.     "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa",
  27.     " Kansas", "Kentucky", "Lousiana", "Maine", "Maryland",
  28.     "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri",
  29.     "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey",
  30.     "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio",
  31.     "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina",
  32.     "South Dakota", "Tennessee", "Texas", "Utah", "Vermont",
  33.     "Virgina", "Washington", "West Virginia", "Wisconsin", "Wyoming"
  34. };
  35.  
  36. void Quiz(void);
  37.  
  38. int main()
  39. {
  40.    
  41.     questionsCorrect = 0;
  42.     printf("Welcome to the States vs. Cities Quiz.\nTo play, type in the number of the state and see if you can get a perfect score.\n");
  43.     system("pause");
  44.  
  45.     srand(time);
  46.  
  47.     clock_t startTime = clock(), elapsedTime;
  48.  
  49.     Quiz();
  50.  
  51.     elapsedTime = clock() - startTime;
  52.  
  53.     if (questionsCorrect > passingScore)
  54.     {
  55.         printf("You got %d out of %d correct!\nThe magic password is PlayAgain.\n", questionsCorrect, totalQuestions);
  56.     }
  57.     else
  58.     {
  59.         printf("You got %d out of %d.\nTry again to unlock the magic password.\n", questionsCorrect, totalQuestions);
  60.     }
  61.  
  62.     int millSec = (elapsedTime * 1000) / CLOCKS_PER_SEC;
  63.     printf("It took you %d.%00d seconds to complete the quiz.\nCan you do it faster?\n", millSec / 1000, millSec % 1000);
  64.  
  65.     system("pause");
  66.     return 0;
  67. }
  68.  
  69. void Quiz(void)
  70. {
  71.     for (int currentQuestion = 1; currentQuestion <= totalQuestions; currentQuestion++)
  72.     {
  73.         int stateNumber = rand() % 3;
  74.         int response = 0;
  75.         printf("Question %d:\n", currentQuestion);
  76.         printf("1.%s\n", (stateNumber == 0) ? states[rand() % stateCount] : cities[rand() % citiesCount]);
  77.         printf("2.%s\n", (stateNumber == 1) ? states[rand() % stateCount] : cities[rand() % citiesCount]);
  78.         printf("3.%s\n", (stateNumber == 2) ? states[rand() % stateCount] : cities[rand() % citiesCount]);
  79.         scanf("%d", &response);
  80.  
  81.         if (response == (stateNumber + 1))
  82.         {
  83.             printf("Correct!\n\n");
  84.             questionsCorrect++;
  85.         }
  86.         else
  87.         {
  88.             printf("Wrong!\n\n");
  89.         }
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement