Originally Posted by
Adak
Vipur, two things you have to know to work forums like these:
1) Start your *own* thread, for your problem. With very few exceptions, you'll be way better off.
2) Get into the *right* forum.
This is the C forum, not the C++ forum, and C doesn't have classes at all.
Get over to our C++ forum.
Eman:
====
For school assignments, I prefer Borland Turbo C/C++, myself. That's what I used to work on your program, btw.
I believe if you add a few things to the program I pared down for you, you'll have better luck than trying to use the bloated program, as the "backbone", and just trim it down and make it work right.
I killed it (your old program), at least once, trying to get it whittled down in size.
If you have any further questions, post up your current version so I'll know where you're at.
Code:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
/*this code is for to ask a number of questions in a quiz contest re-displaying a menu */
main()
{
int i ;
int one=2, two=3, three=4, four=5 ;
int answer1 = 2 ;
int answer2 = 9 ;
int answer3 = 24;
int answer4 = 100;
char yesno ;
int num1 = 0;
int option = 0 ;
do
{
printf(" \n ") ;
printf(" ((----))\n") ;
printf(" <--<\\\\_//>->\n") ;
printf(" | | \n") ;
printf(" (===)\n") ;
printf("\n") ;
printf(" QUIZZITCH CUP\n") ;//This is just some drawing of the prize cup that the winner would have
printf("\n") ;
printf("1. Enter the number of questions to be asked for this round of the quiz\n") ;
printf("2. Start quiz\n") ;
printf("3. Display the numbers of questions that were (i) correctly (ii) incorrectly\n") ;
printf("4. Exit Program\n") ;
scanf("%d", &option) ;//waits for an input for 1, 2, 3 or 4
while(option != 1&&option!=4&&option!=3) //if option is not =1 it willforce user to enter1. but if user chooses 3..it would go to the other while loop//this enables it to display the results of option3 if variable num1 isn't empty. if it is empty and user chose 3..then menu would be redisplayed
{
printf("You must choose 1 before you can proceed to quiz\n") ;
scanf("%d", &option) ;
if(option==4)
{
return 0 ;
break ;
}
i++ ;
}
switch(option) //the switch option allows me to choose number of questions i want .
{
case 1:
{
printf("1. One question\n") ;
printf("2. Two questions\n") ;
printf("3. Three questions\n") ;
printf("4. Four questions\n") ;
scanf("%d", &num1) ; //this scanf to read in the option for the number questions to be answered
while(num1 != 1 && num1 != 2&& num1 != 3 && num1 != 4)
{
printf("You must choose from 1-4 before you can proceed to quiz\n") ;
scanf("%d", &num1) ;
i++ ;
}
clrscr() ;
}
case 2:
{
switch(num1)//start of option 2 using num1 as a variable of numbers of questions to be asked
{
case 1:
{
printf("What is 1+1: *\n") ;
scanf("%d", &answer1) ;//the answer is stored in a variable one, two, three, four, and matched with answer1-5. if it matches..then result is display
break;
}//end of case 1 of question 1
case 2:
{
for(i=0; i<num1; one++, i++)
{
printf("what is %d * %d\n", one, (i+1*3)) ;
scanf("%d", &answer2) ;
}
break ;
}//end of question 2
//case 3
case 3:
{
for(i=0; i<num1; i++)
{
printf("what is %d - %d\n",(one*2)-(i-3), one*=2) ;
scanf("%d", &answer3) ;
}
break ;
}
case 4:
{
for(i=0; i<num1; i++,four+=3)
{
printf("what is %d * %d\n", four, (four*2)-(i+3)) ;
scanf("%d", &answer4) ;
}
break ;
}
}
break ;
}//end of case 2 of switch(option)
case 3: //beginning of case 3. case 3 shows how many questions the user answer correctly
{
if(option == 3 && num1 == 0)
{
printf("You haven't answered question\n") ;
break ;
}
if(num1==1)
{
//by checking the various possibilities the user could have answered the question
if(one==2)
{
printf("i. You got 1 Correct!\n") ;
}
else
{
printf("ii. You got 1 Incorrect!!\n") ;
}
break ;
}
if(num1==2)
{
if(one == 2 && two == 9)
{
printf("i. You got 2 Correct!\n") ;
printf("ii. You got none Incorrect!!\n") ;
}
else if(one == 2 && two!= 9||one!=2 && two == 9)
{
printf("i. You got 1 Correct!\n") ;
}
else
{
printf("ii. You got Everything Incorrect!!\n") ;
}
break ;
}
if(num1==3)
{
if(one != 2 && two !=9 && three == 24||one != 2 && two == 9 && three != 24||one == 2 && two != 9 && three != 24)
{
printf("i. You got 1 Correct!\n") ;
printf("ii. You got 2 Incorrect!!\n") ;
}
else if(one == 2 && two == 9 && three != 24||one != 2 && two == 9 && three == 24||one == 2 && two != 9 && three == 24)
{
printf("i. You got 2 Correct!\n") ;
printf("ii. You got 1 Incorrect!!\n") ;
}
else if(one==2 && two==9 && three==24)
{
printf("i. You got Everything Correct\n") ;
}
else
{
printf("i. You got Everything Incorrect!!\n") ;
}
}
if(num1==4)
{
if(one == 2 && two !=9 && three != 24 && four != 100||one != 2 && two == 9 && three != 24 && four != 100||one != 2 && two != 9 && three == 24 && four!= 100||one != 2 && two != 9 && three != 24 && four==100)
{
printf("i. You got 1 correct!\n") ;
printf("ii. You got 3 incorrect!!\n") ;
}
else if(one != 2 && two != 9 && three == 24 && four == 100||one == 2 && two == 9 && three != 24 && four != 100|| one != 2 && two == 9 && three == 24 && four != 100|| one == 2 && two != 9 && three != 24 && four == 100)
{
printf("i. you got 2 correct\n") ;
printf("ii. you got 2 incorrect\n") ;
}
else if(one != 2 && two == 9 && three == 24 && four == 100||one == 2 && two != 9 && three == 24 && four == 100||one == 2 && two == 9 && three != 24 && four== 100||one == 2 && two == 9 && three == 24 && four!= 100)
{
printf("i. You got 3 Correct!\n") ;
printf("ii. You got 1 Incorrect!!\n") ;
}
else if(one == 2 && two == 9 && three == 24 && four == 100)
{
printf("i. You got everything Correct\n") ;
}
else
{
printf("i. you got everything Incorrect\n") ;
}
break;
}
break ;
}//end of switch(num1)
case 4:
{
printf("Are you sure you want to exit quiz?\n") ;
printf("Y/N") ;
printf("\n") ;
scanf("%1s", &yesno) ;
if(yesno== 'Y'|| yesno == 'y')
{
exit(0) ;
}
clrscr() ;
break ; /*user must input y to quit*/
}
default:
{
printf("Can't you follow simple instructions?\n") ;
break ;
}
}
}while(option==1 || option==2 ||option==3 || option == 4) ;
getch() ;
}
As you can see the code creates a semblance of randomness..i just have to figureout how to store the answers in a way that it won't overwrite the previous one..iwill look at ur example and see how to do it..and how to change option 3 as well..thanks man..pls tell me if option 2 is now better than before..
yeah Borland C..is alright..but it is dimmer and makes my eyes sore..how didu get visual studio or C++ to compile for u? it doesnt work for me