Coding an assignment in C.. please help?

Pages: 12

A college offers a course that prepares students for a state exam for real estate brokers. you have been asked to write a program to summarise the result of 15 students that sat the exam that year. ou have been given a list of the students andnext to each name of the student a 1 is written if the student passed and a 2 if they failed.
your progam should analyse the results as follows
A) input each test result (1 2 or 2), display the program display "enter result" each time the progrm requests another result.
B)count the number of test results of each type
C) display a summary on screen of the test result indicating the number of student who passed or failed
D)if more than 10 passed print the message "bonus to the instructor"

I have that as an assignment and I'm not even sure where to start.. Can someone please help

by the way, I'm new to C and new to this site. So hello :)
Not gonna write this for you, but to get you started it seems like you just need an integer array with 15 elements, then loop through it to input the results (1 or 2), then loop through it again to count the # of passes and fails, then display the results.
That sounds pretty hard...
It's really not that bad. What do you know about loops, arrays, input, and output? That's really all you need.
uh not a lot, if anything really... we just get handed out pages of code and are told to write it and then that's it. So to be honest, I'd say I know nothing..
Haha I had a programming class like that once too. Pretty bad way to actually learn anything. There are good resources online that can help you understand loops, arrays, input, and output, but I can't go find them now. I'm sure if you just google "c arrays tutorial" or something, you'll get all the information you need. Or you could just look for examples in the code he's handed out where arrays, loops, or input and output are used. You just need to take a stab at writing the code, then we can help you fix it from there.
I'll see how it goes. thanks for the help :)
:S it doesn't make any sense to me...
Take it one step at a time. Can you make an array? Can you make a for loop? If so, you're pretty much done.
I'm trying to make an array right now but I'm getting an errors with the code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <stdio.h>
int main ()
{
    int arr[3];

arr[0] = 100 ;
arr[1] = 200 ;
arr[2] = 300 ;
char str[10] = {'c','','p','r','o','g','r','a','m','\0'} ; 
printf( "first: %d\n" , arr[0]);
printf( "second: %d\n" , arr[1]);
printf( "Third: %d\n" , arr[3]);
printf( "string: %s\n" , str );


return 0 ;
}
Last edited on
Alright well first off you're missing a semi colon after your array declaration. That'll clear up some errors.
I believe you can declare char arrays more simply:
 
char str[] = "c prgram";


For your third output statement, you have arr[3] instead of arr[2].

In general, you should post the errors you're getting, not just that you're getting them :)
Last edited on
That worked freddy, thanks. You think they'd put that in the book as opposed to the other one...
it compiles and executes fine, but i don't understand how i can incorporate that into my assignment
Last edited on
Ok, well you now know how to make an integer array and set its elements, and output elements of an array. You now need to learn about loops, and once you get those input is pretty easy, so we'll be able to put it all together in your program.

Edit: For this program, a For loop will make the most sense, so go google those.
Last edited on
Is this a loop
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <stdio.h>
int main()
{
    int i, j ; 
    for( i = 1 ; i < 5 ; i++ )
    {
         printf( " Outer loop iteration %d\n" , i ) ;
    for( j = 1 ; j < 5 ; j++)
         {
              printf( "\tlnner loop iteration %d\n" , j ) ;
         }
     }
return 0;
         }

That was something we did in class the other day
Last edited on
Yes, that is in fact two loops, one within the other. For your program, you'll need just a single loop that goes from 0 and stops at 15.
So, how do I combine them? Sorry about all the questions. I really appreciate everything :)
You'll want to declare an array of 15 elements (just like you declared the one of 3). Then, you'll want a for loop that runs from 0 up to 15 (the ones in your example run from 1 up to 5, so use that as a reference). Within the for loop, you want to ask the user for input as the assignment says, and put their input into the ith element of the array. You do this the same way you did arr[0] etc. earlier, except now it will be arr[index].

To throw you a bone here, this is what should be inside your loop:
 
scanf("Enter Result: %d", arr[i]);


This outputs the "Enter Result: " string, then stores their input into the ith element of the array.
Last edited on
Is this right? I dont understand what to do with the
scanf("Enter Result: %d", arr[i]);

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
int main ()
{
    int arr[16];
arr[0] = 100 ;
arr[1] = 200 ;
arr[2] = 300 ;
arr[3] = 400 ; 
arr[4] = 500 ; 
arr[5] = 600 ; 
arr[6] = 700 ; 
arr[7] = 800 ; 
arr[8] = 900 ;
arr[9] = 1000 ; 
arr[10] = 1100;
arr[12] = 1200 ; 
arr[13] = 1300 ;
arr[14] = 1400 ; 
arr[15] = 1500 ; 

char str[] = "c program" ; 

printf( "1: %d\n" , arr[0]);
printf( "2: %d\n" , arr[1]);
printf( "3: %d\n" , arr[2]);
printf( "4: %d\n" , arr[3]);
printf( "5: %d\n" , arr[4]);
printf( "6: %d\n" , arr[5]);
printf( "7: %d\n" , arr[6]);
printf( "8: %d\n" , arr[7]);
printf( "9: %d\n" , arr[8]);
printf( "10: %d\n" , arr[9]);
printf( "11: %d\n" , arr[10]);
printf( "12: %d\n" , arr[11]);
printf( "13: %d\n" , arr[12]);
printf( "14: %d\n" , arr[13]);
printf( "15: %d\n" , arr[14]);
printf( "16: %d\n" , arr[15]);

printf( "string: %s\n" , str );


return 0 ;
}
Oh the code I posted was for your actual program, not this test one. To do your above code with loops, it would be:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <stdio.h>
int main ()
{
int arr[15];

for (int i = 0; i < 15; i++)
{
    arr[i] = (i + 1) * 100;
}
char str[] = "c program";

for (int i = 0; i < 15; i++)
{
    printf("%d: %d\n", i+1, arr[i]);
}
printf("string: %s\n", str);

return 0;
}


Edit: then to do the for loop for your program, it would be:
1
2
3
4
for (int i = 0; i < 15; i++)
{
    scanf("Enter Result: %d", arr[i]); 
}


This for loop will complete the "A" section of your program instructions.
Last edited on
Pages: 12