Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,920 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,016 people online right now. Registration is fast and FREE... Join Now!




Student's Quiz

 
Reply to this topicStart new topic

Student's Quiz

emotakoh
4 Jan, 2008 - 07:46 PM
Post #1

New D.I.C Head
*

Joined: 1 Oct, 2007
Posts: 4


My Contributions
I need a c program that will output that gets the grades (percentage) of each of the 5 students from 3 quizzes. The program should compute for the averages of the 5 students.


I tried it so many time but many times I failed hers is my code:

CODE
#include<stdio.h>
#include<string.h>
main()
{
    int num[5][3],
    k,l;
    clrscr();
    for(k=0;k<5;k++)
        printf("Enter a student name : \n");
            scanf("%s \n",&num[k]);
    for(l=0;l<3;l++)
        printf("Enter quiz: \n");
            scanf("%d \n",&num[l]);

        {
        for(k=0;k<5;k++)
            for(l=0;l<3;l++)
            printf("%s \t",num[k][l]);
                printf("\n");
        }

{
    int num[80];
    int k,l,TOTAL,AVE,QUIZ;
    clrscr();
        for(k=0;k<5;k++)
        {
        TOTAL[k]=0;
            for(l=0;l<3;l++)
            TOTAL[k]+=QUIZ[k],[l];
            AVE[k]=TOTAL[k]/3;
        }

getch();
}

Please help sos!!!

This post has been edited by jjhaag: 4 Jan, 2008 - 07:58 PM
User is offlineProfile CardPM
+Quote Post

salindor
RE: Student's Quiz
4 Jan, 2008 - 08:03 PM
Post #2

D.I.C Head
Group Icon

Joined: 10 Nov, 2006
Posts: 156



Thanked: 4 times
Dream Kudos: 50
My Contributions
Logically following your program you are on the right track. The problem is with your scoping.

The following should be taken with a grain of salt; but in C all lines either end with a semicolon or a use brackets.

For example you have
CODE

for(k=0;k<5;k++)
   printf("Enter a student name : \n");


you could treat this as a single line. However, what you really wanted was:
CODE

for(k=0;k<5;k++)
{
   printf("Enter a student name : \n");
   scanf("%s \n",&num[k]);
}


This causes the for loop to loop on all the statements inbetween the brackets instead of just the first line like you had before.

Another interesting thing you have in your code is the following structure:
CODE

{
     //code here
}
{
    //code here
}    

While syntatically there is nothing wrong with this; it might be confusing you. Braces like this is used to limit scope; however, because you don't declare any variables within the block, they will descope with the }. Sinse you don't declare any variables they don't do anything.

Salindor
User is offlineProfile CardPM
+Quote Post

emotakoh
RE: Student's Quiz
5 Jan, 2008 - 06:30 PM
Post #3

New D.I.C Head
*

Joined: 1 Oct, 2007
Posts: 4


My Contributions
wow thank you very much that you help me I am so grateful!
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 02:44PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month