#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    4
    Rep Power
    0

    Coding an assignment in C..


    I've been asked to do an assignment that does the following
    A) input each test result (1 2 or 2), display the program display "enter result" each time the program 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"

    So far what I've managed to do, with help, is this:

    Code:
    #include <stdio.h>
    int main ()
    {
    int arr[15]; //declares integer array with 15 elements
    
    for (int i = 0; i < 15; i++)  // i starts at 0, and will increase by 1 each time the loop runs
    // once i reaches 15, the loop will stop executing, because arr[15] is outside of our array
    {
        arr[i] = (i + 1) * 100; // In your test program you assign 100 to element 0,
    // 200 to element 1, and so on
    // this statement takes the element number (i), adds 1, then multiplies by 100 to get 100 for element 0, 200 for element 1, etc
    }
    char str[] = "c program"; // this is unchanged
    
    for (int i = 0; i < 15; i++)  // same loop as used before
    {
        printf("%d: %d\n", i+1, arr[i]); //we want to print 2 numbers, the element number + 1 and the value in the array at that element
    //so we do i+1 to get "1" to print for the value in the 0th element
    }
    printf("string: %s\n", str); // this is unchanged
    
    return 0;
    }
    I believe it covers part "A" of the assignment, could someone direct me and give help with the rest? thanks
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,387
    Rep Power
    1871
    > I believe it covers part "A" of the assignment, could someone direct me and give help with the rest? thanks
    Your program has NO input at all, so how can it possibly deal with " input each test result (1 2 or 2), display the program display "enter result" "

    Looks to me like you posted the code for your previous assignment.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    4
    Rep Power
    0
    Originally Posted by salem
    > I believe it covers part "A" of the assignment, could someone direct me and give help with the rest? thanks
    Your program has NO input at all, so how can it possibly deal with " input each test result (1 2 or 2), display the program display "enter result" "

    Looks to me like you posted the code for your previous assignment.
    Oh...could you help me make the part A
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,854
    Rep Power
    481
    This comment is incorrect:
    // once i reaches 15, the loop will stop executing, because arr[15] is outside of our array


    The loop terminates because i would not be less than 15. arr[15] is not considered in this decision.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo