top of page

Fun Quiz Game Using C Programming | C Programming Assignment Help

Sep 30, 2022
3 min read

Requirement Details

Make sure in this quiz it contains the following


  • selection (if or switch case),

  • repetition (for or/and while or/and do while)

  • at least one function with an array of struct in the input parameter list; the array of struct is declared in main (or another function) and this function must set values in the array of struct, and the calling function (main or other) must make use of the array of struct on return (you choose whether to pass by value or pass by address)

  • at least one function with a pointer to a variable of type char, int, float or double in the parameter list; the function must set the contents of the variable, and the calling function (main or other) must make use of the variable on return

  • your program needs several instances where the user must input commands from the keyboard in order to interact with the program

  • your program must loop to the start allowing the user to run through the program time after time (this is an independent requirement from the second point to use repetition).


Implementation

//This is a simple quiz test programmed in c
//The data of quiz is coming from quiz.csv file
//Once the quiz starts, here the user needs to answer each question one by one
//for each question, we display the question and then its four options
//now the user is prompted to input the answer (1, 2, 3 or 4 which represent option A, option B, option C or option D respectively)
//now once the user enters the answer, we check if the user entered answer is correct
//if answer is correct +4 marks are awarded
//if its incorrect -1 marks are awarded
//current score is always displayed in the screen
//after the test is done, the user is shown the final score he/she obtained from say 20 marks(since here we are only having 5 questions and each question has 4 marks so, 5*4 = 20)
//after that the user is asked whether he wants to restart the quiz (0, 1)
//here 1 means he wants to restart and 0 means he wants to exit

//include header files
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//Creating structure using struct keyword to declair the variables
typedef struct
{
    char question[1024];
    char optionA[1024];
    char optionB[1024];
    char optionC[1024];
    char optionD[1024];

    int answer;

} CHALLENGE;//defining the type "CHALLENGE" in form of structure, in simple terms it would represent our question, its 4 options and its answer.


//just prints the question along with its multiple choices
void printQuestion(CHALLENGE* question, int * questionNumber){
  printf("Q%d. %s; \n\n", *questionNumber + 1, question->question);
  printf("(1). %s; \n", question->optionA);
  printf("(2). %s; \n", question->optionB);
  printf("(3). %s; \n", question->optionC);
  printf("(4). %s; \n\n", question->optionD);
}


//imports questions from quiz.csv file, here in the parameter list there is a pointer pointing to array of structures
void importQuestions(CHALLENGE* questions){
 FILE* fp = fopen("quiz.csv", "r");
		// Here we have taken size of
		// array 1024 you can modify it
		char buffer[1024];

		int row = 0;
		int column = 0;



		while (fgets(buffer,
					1024, fp)) {
			column = 0;

			char* value = strtok(buffer, ";");
   CHALLENGE question;

			while (value) {
				if (column == 0) {
     strcpy(question.question, value);
				}

    if (column == 1) {
     strcpy(question.optionA, value);
				}

    if (column == 2) {
     strcpy(question.optionB, value);
				}

    if (column == 3) {
     strcpy(question.optionC, value);
				}

    if (column == 4) {
     strcpy(question.optionD, value);
				}

    if (column == 5) {
     question.answer = atoi(value);
				}

    
				

				value = strtok(NULL, ";");
				column++;
			}
   questions[row] = question;
   row++;
		}
  
		// Close the file
		fclose(fp);
}

//it takes in questionNumber and then asks the question by printing it, then asking for user input and finally checking whether the entered answer is correct
int askQuestion(CHALLENGE* questions, int questionNumber){
   int gotItRight = 0;
   
   printQuestion(&questions[questionNumber], &questionNumber);
   printf("\n");
   printf("Enter Answer: ");
   int userAnswer;
   scanf("%d", &userAnswer);
   if(userAnswer == questions[questionNumber].answer)
   printf("Right Answer!!!"), gotItRight = 1;
   else
   printf("You got it wrong !\nCorrect answer is option number: %d\n\n", questions[questionNumber].answer);
   getchar(); 

   return gotItRight? 4: -1;
}

//set the exitGame variable a value of 0;
void setExitGame(int *exitGame){
 *exitGame = 0;
 return;
}

// Driver Code
int main()
{
  start:
  int restart = 0;
  CHALLENGE* questions = malloc(1000 * sizeof *questions);
	importQuestions(questions);

  int exitGame;
  setExitGame(&exitGame);
  int totalScore = 0;
  int i = 1;
  printf("Lets start the quiz!!!\n\n");
  printf("You will be asked 5 questions, for correct answer you get +4 and for incorrect you get -1");
   printf("\nPress Any Key to Continue\n");  
   getchar();
  while(!exitGame){
   system("cls");
   printf("Your Current Score is: %d\n\n", totalScore);
   totalScore += askQuestion(questions, i-1);
   printf("\nNow Current Score is: %d\n", totalScore);

   if(i == 5)
   exitGame = 1;
   i++;
   printf("\nPress Any Key to Continue\n");  
   getchar(); 
  }
  system("cls");
  printf("Your got %d, out of %d\n", totalScore, 20);

  printf("Do you want to restart(0/1)?\n");
  scanf("%d", &restart);
  if(restart)
  goto start;
  
	
	return 0;
}

Output:






Go get other C programming related help you can send your requirement details at:


realcode4you@gmail.com

9 Comments


Xoso 66 giúp mình hình dung rõ hơn cách một phiên sử dụng được tiếp nối khi thay đổi thiết bị. Mình thường xem Casino trên máy tính rồi chuyển sang Thể thao bằng điện thoại để quan sát sự khác biệt trong cách trình bày. Trên PC, mình có thể nhìn tổng thể các khu vực trước khi lựa chọn, còn màn hình nhỏ khiến mình tập trung vào từng bước cụ thể. Khi các danh mục chính vẫn giữ cách phân chia quen thuộc, mình dễ nhận biết hướng cần tìm dù bố cục thay đổi. Qua nhiều lần thử, mình dần điều chỉnh cách thao tác theo từng thiết bị. Với mình, sự liên kết này giúp quá…

Like

https://lx88win.quest/xo-so-lx88/ làm tôi chú ý đến cách hiển thị thông tin tài khoản và những chức năng quản lý cá nhân. Khi xem xét cấu trúc trang, tôi thường tìm khu vực lịch sử hoạt động, thông tin giao dịch và các thiết lập liên quan đến tài khoản. Những danh mục như bóng đá, game bài và casino trực tiếp nên được tách khỏi phần quản lý để hạn chế nhầm lẫn khi thao tác. Tôi cũng quan tâm đến việc các thông báo xác nhận có nêu rõ trạng thái và bước tiếp theo hay không. Nếu nội dung giao dịch chưa hoàn tất, người dùng cần có thông tin dễ hiểu để biết cách kiểm tra thay vì…

Like

slotbm88 com giúp tôi đánh giá cách tổ chức thông tin khi trang có nhiều nhóm nội dung khác nhau. Tôi quan sát thứ tự xuất hiện của danh mục, độ nổi bật của tiêu đề và khoảng cách giữa các thành phần để xem bố cục có dễ theo dõi không. Khi tìm qua nổ hũ, game bài, casino và xổ số, tôi chú ý khả năng phân biệt từng nhóm mà không phải đọc quá nhiều mô tả. Những chức năng như đăng nhập, lịch sử giao dịch và hỗ trợ cũng cần được đặt ở vị trí dễ ghi nhớ. Tôi ưu tiên cách trình bày có phân cấp rõ ràng, trong đó nội dung chính dễ nhận…

Like

https://bbm88.ink/ cho mình cảm giác chủ động hơn khi bắt đầu quan sát cả những thao tác ngoài phần trò chơi. Mình thường kiểm tra thông tin tài khoản trước rồi mới lựa chọn nội dung muốn trải nghiệm. Có phiên mình theo dõi Thể thao với các trận tennis, sau đó chuyển sang Xổ số để xem kết quả ba miền. Khi cần kiểm tra lịch sử giao dịch, mình tạm mở phần liên quan rồi tiếp tục hoạt động đang quan tâm. Sau nhiều lần sử dụng, mình đã quen với vị trí của những mục thường dùng nên việc chuyển đổi cũng nhẹ nhàng hơn. Cách sắp xếp hoạt động này khá phù hợp với mình khi một…

Like

88VBET NAME khiến mình để ý đến sự khác nhau giữa trải nghiệm trực tiếp và nội dung mô phỏng. Thể thao ảo có các trận ngắn, hoạt động 24/7 và sử dụng RNG để tạo kết quả, nên nhịp tiếp cận khá khác với việc theo dõi một trận thể thao thực tế. Mình thấy điểm đáng quan sát nằm ở cách người dùng được chuyển từ một kiểu trải nghiệm sang kiểu khác mà vẫn nhận biết được mình đang ở nhóm nào. Đây cũng là lý do mình quan tâm đến khả năng phân tách nội dung. Khi mỗi loại có đặc trưng rõ ràng, việc khám phá nhiều khu trở nên dễ hình dung hơn.

Like

REALCODE4YOU

Realcode4you is the one of the best website where you can get all computer science and mathematics related help, we are offering python project help, java project help, Machine learning project help, and other programming language help i.e., C, C++, Data Structure, PHP, ReactJs, NodeJs, React Native and also providing all databases related help.

​

Hire Us to get Instant help from realcode4you expert with an affordable price.

USEFUL LINKS

Discount

ADDRESS

Noida, Sector 63, India 201301

Follows Us!

  • Facebook
  • Twitter
  • Instagram
  • LinkedIn

OUR CLIENTS BELONGS TO

  • india
  • australia
  • canada
  • hong-kong
  • ireland
  • jordan
  • malaysia
  • new-zealand
  • oman
  • qatar
  • saudi-arabia
  • singapore
  • south-africa
  • uae
  • uk
  • usa

© 2026 IT Services provided by Realcode4you.com

bottom of page