Quiz

Program to create an on line quiz

Page 1 of 1

4 Replies - 2106 Views - Last Post: 02 March 2008 - 10:16 AM Rate Topic: -----

#1 dhurdell  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 01-March 08

Quiz

Post icon  Posted 01 March 2008 - 01:03 PM

I am working on a quiz program in C, when the code reads the answer from the student it does save it right, but when i compare it in my IF statement, is not comparing ok. Could you tell me what am I doing wrong?. This is a beginner level program.
Thanks.

#include<stdio.h>
#include<string.h>
#include<stdlib.h>

char Question1[ ]   = "What is a float\n";
char Answer1[ ]	 = "\ta. A decimal number. \n\t\tb. A String.  \n\t\tc. An Integer Number.   \n\t\td. None of the above.";
char Answer_Key1[1];

int  Right,Wrong,i;
char Stop, Grade;

char  Name[30];
float Percentage;
char  Student[1]; 

void Print_Out(int i,int Right,int Wrong,float Percentage,char Grade,char Name[30]);
char Grading(int Right, int Wrong);



main(void)
{

Percentage = 0.0;
Right = 0;
Wrong = 0;
i = 1;
Answer_Key1[1] = 'a';
Answer_Key2[1] = 'b';
Answer_Key3[1] = 'c';
Answer_Key4[1] = 'd';
Answer_Key5[1] = 'c';

printf("\n\tHello! Welcome to your quiz...\n");
printf("\tPlease type in your name :\t");
gets( Name );
printf("\n\n\tOK lets  start!...\t");
puts( Name );
printf("\n\n");



	
	printf("\n\nQuestion %d:\t%s",i, Question1);
	printf("\t%s\n\n",Answer1);
	printf("\n\nChoose your answer :\t");
	scanf("%s", Student);
	

	printf("\n\tTesting the answer key --- Answer key is : %c\n",Answer_Key1[1]);

	printf("\n\tTesting the student answer ---- student answer is: %s\n",Student);

	if (Answer_Key1 == Student)
	{	printf("\n\nGood!\n\n");
		Right++;
	}
	else
	{	printf("\n\tWrong!\n\n");
		Wrong++;
	}

	i++;

	Grading(Right, Wrong);
	Print_Out(i,Right,Wrong,Percentage,Grade,Name);
	
	return 0;
}

/*  Functions */

char Grading(int Right, int Wrong)
{
			Percentage = ((float)Right/((float)Right + (float)Wrong))*100;

			if (Percentage >=90.0)
				Grade = 'A';
			else if ((Percentage >= 80.0) && (Percentage <= 90.0))
				Grade = 'B';
			else if ((Percentage >= 70.0) && (Percentage <= 80.0))
				Grade = 'C';
			else if ((Percentage >= 65.0) && (Percentage < 70.0))
				Grade = 'D';
			else
				Grade = 'F';
			return Grade;
	
}

void Print_Out(int i,int Right,int Wrong,float Percentage,char Grade,char Name[30])
{
		printf("\n\n\n %s	\n\n",Name);
		
		printf("   Total Questions\tRight Answers\tWrong Answers\tPercentage\tGrade\n");
		printf("   ===============\t=============\t=============\t==========\t=====\n");
		printf("%12d%18d%16d%16.0f	 %8c\n",(i-1),Right,Wrong,Percentage,Grade);
}


*Mod Edit: added code tags: :code:

Is This A Good Question/Topic? 0
  • +

Replies To: Quiz

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1633
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Quiz

Posted 01 March 2008 - 01:36 PM

Please post your code in code tags => :code:
Was This Post Helpful? 0
  • +
  • -

#3 Jingle  Icon User is offline

  • D.I.C Regular

Reputation: 9
  • View blog
  • Posts: 317
  • Joined: 20-October 07

Re: Quiz

Posted 01 March 2008 - 03:22 PM

i sugest you do

percent = right / totalPosible *100

truth is I'm not really sure what your trying to do.
Was This Post Helpful? 0
  • +
  • -

#4 Mikhail  Icon User is offline

  • Bastard Operator From Hell
  • member icon

Reputation: 58
  • View blog
  • Posts: 1,378
  • Joined: 26-October 07

Re: Quiz

Posted 01 March 2008 - 07:03 PM

What I think he is trying to do is create a quiz that could be taken online, if so you can't do that with C at least not on the internet instead use this PHP,JScript,ASP.net stuff and other things however you wont be able to view the quiz online since C is a System Programming language. So you could do it using other language. But C wont do it as it is not designed for that.
Was This Post Helpful? 0
  • +
  • -

#5 red_4900  Icon User is offline

  • Code T(h)inkers
  • member icon

Reputation: 21
  • View blog
  • Posts: 1,119
  • Joined: 22-February 08

Re: Quiz

Posted 02 March 2008 - 10:16 AM

what error went out? I just assume the code is not one for online, and I'm still trying to figure out what some of your code mean.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1