Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello all...
...I'm a rather frustrated first-year student struggling to get to grips with C. (I don’t expect anyone to do my homework, so please read on : )
Having passed 4 perception tests, the time has come to build my first C program. (Not "Hello world, this is my first C program!" either!!)
The idea is simple:
"...design a program which will generate a Multiple Choice Objective Question (MCOQ) test that examines 5 aspects of the C programming language. The test is to consist of 5 questions (one for each aspect), each question having 4 possible answers, only one of which is correct. After the user has attempted the test, the program should display the score and print out those questions for which the user selected the incorrect answer. The layout of the screen is up to you."Being new to C my knowledge of the language is fragmented and disjointed. Constantly reading through study a pack hasn’t filled any blank spaces created in my mind, or linked together any concepts I have grasped from practical labs/tests.
Ultimately, I guess I'm looking for some expert advice/resources on where to start not just with this assignment, but with conquering my fear of the C language itself!
Cheers everyone, MiKeY.

I suggest you create a few structures, which may look like this:
typedef enum BOOLEAN {FALSE, TRUE};
typedef answer_record {
unsigned char answer_number;
char *answer_text;
BOOLEAN is_correct;
}ANSWER;typedef query_record {
unsigned char number;
char *question;
ANSWER answer[4];
}QUERY;/* this is your 5 questions array, each of
them can have 4 possible answers, but only
on is the correct answer. */QUERY my_querry[5];
Then going through them, one by one, fill up with details. Don't worry too much about the display. Just get the basic loop to work with first, ie. listing out questions and possible answers, then get the input from the user. Something like:
void main (void)
{
unsigned char q_number = 1;
BOOLEAN is_correct = FALSE;fillup_query();
for{;;} /* loop forever */
display_queries(q_number);
answer_number = get_answer();
is_correct = (my_query[q_number].answer[answer_number].is_correct == TRUE);
if {is_correct} {
display_praise_message();
q_number++;
if {q_number > 5}{
/* end program here */
exit(1);
}
} else {
display_humiliating_message();
/* for getting the question wrong :0) */
}
}
}I hope that you can work out the details for the basic routines.

You need a tutorial off the Internet. Just find one with Google. I would recommend you find two or three. Having the same information fed in different ways can really help. Try to stay in the context of your course material so as to complete the assignment correctly.
Think in steps. Then group the steps around conditions. Then tie the conditions to one another. Read this paragraph again.
Your program is going be simple (Standard I/O). Print a question to the screen (a string of text), break a new line, print answer A, break another line, print answer B, etc. Once this command has been completed, accept a user prompt for input on a new line. Only allow the characters you used to denote answers (A, B, C, D maybe). Allow them in any case.
Check the answer right away (simplify the things when possible for later use) and save the result to a variable. You could just add to a single variable. When user input has been saved (and maybe the user has answered a confirmation prompt), continue. This can all be very linear if you choose.
When you have gone through your questions, add up your answers. If you have added them previously to a single variable, then check this. Print the total answers correct, the total answers wrong (a nice touch), and the total number of questions. Give the user a percentage correct and maybe a message apt for their grade.
Example of a program pause (without a system shell call like PAUSE).

Oh by the way, I've forgotten about the lower bound to index array in C is 0 and not 1. So the q_number is really 0, for the first question, and not 1 and the comparison for the end of loop is "q_number > 4" instead of "> 5". The part of the fillup_query() really should be done in "main" or even at the top, where you declare the variable, where you can initialize the record and arrays there.

The best way to learn a language is first to learn all the keywords, and the use of them. Make an example program if you need to experiment with it, then alter the program to your heart contents to find out all the possbilities it can be changed. Do not worry too much about what is available in the libraries, but the core part of the language first. So if you learn "if .. else" statement for instance, write a small programme making use of this, then when you learn about the "switch .. case" statement, comparing the result with "if .. else" and what differences you can draw between the two selective statement (there are differences), and so on, so forth. To know about the limitations of data types, examine the file "limits.h" in the "include" subdirectory.

i like the c language, but it is very hard for me to tell people how they should get started. Well, I would say, do a bit of reading and be familiar with the few most basic keywords and types first, and never never forget to do lots of practice, ie, coding.
i had the same feeling with you about assembly language a few years ago,but after i spent lots of time reading and coding, i eventually love it.
hope that help.
wtk :)

I know a good tutorial site :)
http://www.cplusplus.com/doc/tutorial/
it's good. It's how i learnt C and C++, although I'm still heavily a lamer :)

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |