Need Help quick reply plz

This is a discussion on Need Help quick reply plz within the C Programming forums, part of the General Programming Boards category; Hi. Tomorrow is my programming exam, and today I have pulled out the past exam paper, and I took this ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    13

    Exclamation Need Help quick reply plz

    Hi. Tomorrow is my programming exam, and today I have pulled out the past exam paper, and I took this question out from last semesters exam. I needed help for this question because I was very confused, anywayz, I made an effort to answer this question, anyone can correct me? The question is below in this post, and my answer will be below this post. The part that got me confused is when I reach to the statement “If the counter not equal to zero”. What will be the condition for while (?) ?????

    ----------------------------------------------------------------------------------------------


    (Exam Question): Write a program that receives marks and gives the class averages with sentinel-controlled repetition. Use the following algorithms as your guide. (10 marks)

    Initialize total to zero
    Initialize counter to zero
    Input the first mark
    While the user has not yet entered the sentinel value
    Add this mark into the running total
    Add one to the mark counter
    Input the next mark (possibly the sentinel)

    If the counter is not equal to zero
    Set the average to the total divided by the counter
    Print the average
    Else
    Print “No marks were entered”

    ---------------------------------------------------------------------------------------------------

    (My Answer): int total=0, counter=0, mark;

    do{
    printf("Plz enter a mark");
    scanf("%d", &mark);

    while (counter!=0){
    ++counter;
    total+=mark;}

    if (counter!=0)
    average = total/counter;
    else
    printf("No marks entered");

    }

    printf("Average is %d", average);

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    14
    (The answer):

    int total=0, counter=0, mark = 0, average;

    do{
    printf("Plz enter a mark");
    scanf("%d", &mark);

    counter++ ;
    total+=mark;

    } while (mark > 0) ;


    if (counter!=0)
    average = total/(counter-1);
    else
    printf("No marks entered");


    printf("Average is %d", average);

    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault -- Plz Help Quick
    By djwicks in forum C Programming
    Replies: 1
    Last Post: 04-10-2005, 10:08 AM
  2. Quick Reply or Normal Reply
    By Thantos in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 05-18-2004, 01:49 PM
  3. Quick Reply.
    By Cheeze-It in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 12-07-2002, 02:32 AM
  4. Another urgent help, plz reply fast
    By playboy1620 in forum C Programming
    Replies: 4
    Last Post: 04-11-2002, 06:21 AM
  5. just a reaaaaaaly quick question plz help
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 03-21-2002, 11:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21