473,513 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Making a Quiz with 3 Choices in Turbo C

2 New Member
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. main()
  3. {
  4.   int a,b,c,ans;
  5.  
  6.   printf("\n An airplane travels 280.0m down the runway before taking off.");
  7.   printf("\n If its start from rest, moves with constant acceleration and becomes airborne");
  8.   printf("\n in 8.00s, what is its speed when it takes off?");
  9.  
  10.   printf("\n a. 70m/s");
  11.   printf("\n b. 80m/s");
  12.   printf("\n c. 90m/s");
  13.  
  14.   printf("/nEnter Your Answer in SMALL Letter: ");
  15.   scanf("%d", &ans);
  16.  
  17.  
  18.   if(ans=='a')
  19.   printf("Your Answer is Correct");
  20.   else
  21.   printf("Your Answer is Wrong");
  22.  
  23.  
  24.   printf("\n");
  25.   printf("\nv=2d/t");
  26.   printf("\n2(280.0m)/8.0s");
  27.   printf("\n70m/s");
  28.   printf("\nThe correct answer is a. 70m/s");
  29.   getch();
  30.   }
  31.  
  32.  
  33.  
  34. The Problem is When i type a it prints the answer is wrong ....what i wanty to make when i type a it will print the answer is correc.  can you help me..
Sep 4 '14 #1
1 2305
donbock
2,426 Recognized Expert Top Contributor
The scanf format string for ans is "%d". That puts an integer value in ans. However, the user entered 'a', 'b', or 'c'. None of these are valid integer values, so the format string is not satisfied and ans is not changed. Refer to the manpage for scanf. You want the format specifier for characters ("%c"). Notice that the type of the "%c" argument should be char*, not int*.

By the way, perhaps you want the answers to be case insensitive (either 'a' or 'A' are correct answers) so the student isn't penalized if caps lock is on. Refer to tolower.
Sep 4 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
3798
by: Dave Parrin-Bull | last post by:
Hi all, I have been asked (nay told!) to do a quiz for a webpage at work, now I can do the basic things like getting the radio boxes up there and assign values to them but here is what they...
5
5732
by: Vandana Rola | last post by:
Hello Everyone, I am a beginner in Javascript.I want to create fun quiz tool using javascript (no database). The feature of that tool is every question has five choices. The user needs to select...
16
4161
by: C++ Hell | last post by:
Hey everyone just designing a quiz for school and managed to write the code for the questions and answers thou i have to add scores and at the end an overall score does anyone have any idea what to...
2
3412
by: kenny | last post by:
I'm making a quiz to be posted on the internet. but I'm facing difficulties in finding a simple timer for the quiz (unlimited timing) which will keep on running regardless to the change of the page...
6
2087
by: shror | last post by:
hi every body, i have a problem dealing with a quiz system in php. the idea is that am building a quiz system by giving a question and choices in radio buttons, and after selecting the answer...
1
3070
by: korr | last post by:
Hi there, i'm trying to develop a quiz in flash. Searching on the net, I found a quiz in flashkit from sephiroth.it by Alessandro Crugnola. His quiz has a script that puts the questions and the...
3
3164
by: empiresolutions | last post by:
I making a personality quiz that goes like the following. User takes a test to determine which type of person they are more like. So there will be say 5 types, each given a percentage of 100 that...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7539
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7527
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5686
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3234
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3223
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.