fork download
  1. #include <stdio.h>
  2.  
  3. int main() { char questions[10][300] = { "Question 1: What is the chemical symbol for the element with the highest melting point?\nA. W\nB. C\nC. Os\nD. Fe",
  4. "Question 2: Who is known as the father of modern physics?\nA. Isaac Newton\nB. Albert Einstein\nC. Nikola Tesla\nD. James Clerk Maxwell",
  5. "Question 3: What is the smallest prime number?\nA. 0\nB. 1\nC. 2\nD. 3",
  6. "Question 4: In which year did the Titanic sink?\nA. 1900\nB. 1912\nC. 1920\nD. 1935",
  7. "Question 5: Which planet is known as the 'Red Planet'?\nA. Venus\nB. Mars\nC. Jupiter\nD. Saturn",
  8. "Question 6: What is the hardest natural substance on Earth?\nA. Gold\nB. Iron\nC. Diamond\nD. Graphene",
  9. "Question 7: What is the capital of Canada?\nA. Toronto\nB. Montreal\nC. Vancouver\nD. Ottawa",
  10. "Question 8: Which famous artist is known for painting the Mona Lisa?\nA. Pablo Picasso\nB. Leonardo da Vinci\nC. Vincent van Gogh\nD. Claude Monet",
  11. "Question 9: Who wrote the novel '1984'?\nA. Aldous Huxley\nB. George Orwell\nC. J.K. Rowling\nD. Mark Twain",
  12. "Question 10: What is the longest river in the world?\nA. Nile\nB. Amazon\nC. Yangtze\nD. Mississippi" };
  13. char answers[10] = { 'A', 'B', 'C', 'B', 'B', 'C', 'D', 'B', 'B', 'B' };
  14.  
  15. int rewards[10] = { 100, 500, 1000, 5000, 10000, 20000, 50000, 100000, 500000, 1000000 };
  16.  
  17. char choice;
  18. int score = 0;
  19. int balance = 0;
  20. int i;
  21.  
  22. for (i = 0; i < 10; i++) {
  23. printf("\n %s\n", questions[i]);
  24.  
  25. int valid;
  26.  
  27. do {
  28.  
  29. printf("Your answer (A/B/C/D): ");
  30. scanf(" %c", &choice);
  31.  
  32. switch (choice) {
  33. case 'A':
  34. case 'B':
  35. case 'C':
  36. case 'D':
  37. valid = 1;
  38. break;
  39. default:
  40. printf("Invalid input. Please enter only A, B, C, or D.\n");
  41. valid = 0;
  42. }
  43. } while (!valid);
  44.  
  45. if (choice == answers[i]) {
  46. printf("Correct! You won $ %d\n", rewards[i]);
  47. balance = rewards[i];
  48. score++;
  49. } else {
  50. printf("Wrong! Correct answer was: %c\n", answers[i]);
  51. break;
  52. }
  53. }
  54.  
  55. printf("\nYour final score: %d/10\n", score);
  56. printf("You won: $ %d\n", balance);
  57.  
  58. if (score == 10) {
  59. printf("CONGRATULATIONS! YOU WON $1,000,000!\n");
  60. } else {
  61. printf("Better luck next time.\n");
  62. }
  63.  
  64. return 0;
  65.  
  66. }
Success #stdin #stdout 0.01s 5288KB
stdin
ABCBBCDBBB
stdout
 Question 1: What is the chemical symbol for the element with the highest melting point?
A. W
B. C
C. Os
D. Fe
Your answer (A/B/C/D): Correct! You won $ 100

 Question 2: Who is known as the father of modern physics?
A. Isaac Newton
B. Albert Einstein
C. Nikola Tesla
D. James Clerk Maxwell
Your answer (A/B/C/D): Correct! You won $ 500

 Question 3: What is the smallest prime number?
A. 0
B. 1
C. 2
D. 3
Your answer (A/B/C/D): Correct! You won $ 1000

 Question 4: In which year did the Titanic sink?
A. 1900
B. 1912
C. 1920
D. 1935
Your answer (A/B/C/D): Correct! You won $ 5000

 Question 5: Which planet is known as the 'Red Planet'?
A. Venus
B. Mars
C. Jupiter
D. Saturn
Your answer (A/B/C/D): Correct! You won $ 10000

 Question 6: What is the hardest natural substance on Earth?
A. Gold
B. Iron
C. Diamond
D. Graphene
Your answer (A/B/C/D): Correct! You won $ 20000

 Question 7: What is the capital of Canada?
A. Toronto
B. Montreal
C. Vancouver
D. Ottawa
Your answer (A/B/C/D): Correct! You won $ 50000

 Question 8: Which famous artist is known for painting the Mona Lisa?
A. Pablo Picasso
B. Leonardo da Vinci
C. Vincent van Gogh
D. Claude Monet
Your answer (A/B/C/D): Correct! You won $ 100000

 Question 9: Who wrote the novel '1984'?
A. Aldous Huxley
B. George Orwell
C. J.K. Rowling
D. Mark Twain
Your answer (A/B/C/D): Correct! You won $ 500000

 Question 10: What is the longest river in the world?
A. Nile
B. Amazon
C. Yangtze
D. Mississippi
Your answer (A/B/C/D): Correct! You won $ 1000000

Your final score: 10/10
You won: $ 1000000
CONGRATULATIONS! YOU WON $1,000,000!