Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- const int citiesCount = 35;
- const int stateCount = 50;
- const int totalQuestions = 5;
- const int passingScore = 3;
- int questionsCorrect = 0;
- const char cities[][50] = {
- "Chicago","Los Angeles", "San Francisco", "Orlando", "Seattle",
- "Boston", "Atlanta", "Richmond", "Charleston", "Nashville",
- "Austin", "Houston", "Las Vegas", "Phoenix", "Detroit",
- "Flint", "Portland", "San Deigo", "Philadelphia", "Miami",
- "Tampa", "New Orleans", "Honolulu", "Redmond", "Pittsburgh",
- "Cleveland", "Indianapolis", "Baltimore", "Tallahassee", "Denver",
- "St. Paul", "Helena", "Boise", "Albuquerque", "Santa Fe",
- "Lincoln", "Dallas", "Frankfort", "Chenyenne", "Bismark",
- "Columbus", "Albany", "Charlotte", "Birmingham", "Memphis",};
- const char states[50][50] = {
- "Alabama","Alaska", "Arizona", "Arkansas", "California",
- "Colorado", "Connecticut", "Deleware", "Florida", "Georgia",
- "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa",
- " Kansas", "Kentucky", "Lousiana", "Maine", "Maryland",
- "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri",
- "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey",
- "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio",
- "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina",
- "South Dakota", "Tennessee", "Texas", "Utah", "Vermont",
- "Virgina", "Washington", "West Virginia", "Wisconsin", "Wyoming"
- };
- void Quiz(void);
- int main()
- {
- questionsCorrect = 0;
- 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");
- system("pause");
- srand(time);
- clock_t startTime = clock(), elapsedTime;
- Quiz();
- elapsedTime = clock() - startTime;
- if (questionsCorrect > passingScore)
- {
- printf("You got %d out of %d correct!\nThe magic password is PlayAgain.\n", questionsCorrect, totalQuestions);
- }
- else
- {
- printf("You got %d out of %d.\nTry again to unlock the magic password.\n", questionsCorrect, totalQuestions);
- }
- int millSec = (elapsedTime * 1000) / CLOCKS_PER_SEC;
- printf("It took you %d.%00d seconds to complete the quiz.\nCan you do it faster?\n", millSec / 1000, millSec % 1000);
- system("pause");
- return 0;
- }
- void Quiz(void)
- {
- for (int currentQuestion = 1; currentQuestion <= totalQuestions; currentQuestion++)
- {
- int stateNumber = rand() % 3;
- int response = 0;
- printf("Question %d:\n", currentQuestion);
- printf("1.%s\n", (stateNumber == 0) ? states[rand() % stateCount] : cities[rand() % citiesCount]);
- printf("2.%s\n", (stateNumber == 1) ? states[rand() % stateCount] : cities[rand() % citiesCount]);
- printf("3.%s\n", (stateNumber == 2) ? states[rand() % stateCount] : cities[rand() % citiesCount]);
- scanf("%d", &response);
- if (response == (stateNumber + 1))
- {
- printf("Correct!\n\n");
- questionsCorrect++;
- }
- else
- {
- printf("Wrong!\n\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement