Sponsored Content
Full Discussion: Coursework for to while
Homework and Emergencies Homework & Coursework Questions Coursework for to while Post 302511337 by mgyeah on Wednesday 6th of April 2011 02:34:24 PM
Old 04-06-2011
Coursework for to while

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:
The problem i have would be printf("Average of %u values is %f.\n",n (n == 0) ? 0.0 : (double) sum / n); in the code on #3 because i have no idea what this means and apparently it is the problem for compiling. I have ask a few experience programmers and they say its another way to write a for statement is that true?
I am changing the codes for statement to while just for a heads up.

2. Relevant commands, code, scripts, algorithms:
Code:
/*      File : avg.c            *
 *      By   :                  *
 *      login:                  *
 *      team :                  *
 *      Date :                  */

/*
 * Compute average of its input values.
 */

#include <stdio.h>

int main()
{
  int          next;               /* next input value */
  long         sum;                /* running total */
  unsigned int n;                  /* number of input values */
  int          result;             /* did we read another value? */
  double       avg;                /* average of input values */

        for (sum = n = 0;
             (result = scanf("%d", &next)) == 1;
             n++)
                sum += next;   
        if (result != EOF)
                printf("Warning: bad input after reading %u values\n", n);
        printf("Average of %u values is %f.\n",
               n, (n == 0) ? 0.0 : (double) sum / n);
  
}


3. The attempts at a solution (include all code and scripts):
Code:
/*      File : avg.c            *
 *       *      By   :Matthew Yee                  *
 *        *      login: mgy                 *
 *         *      team : Yun                 *
 *          *      Date : 04/05/2011                 */

/*
 *  * Compute average of its input values.
 *   */

#include <stdio.h>

int main()
{
  int          next;               /* next input value */
  long         sum;                /* running total */
  unsigned int n;                  /* number of input values */
  int          result;             /* did we read another value? */
  double       avg;                /* average of input values */
  sum = n = 0;
       

     while(result = scanf("%d", &next) == 1){
            n++; 
            sum += next; } 
            
                // n++;
                //sum += next;   
        if (result != EOF)
                printf("Warning: bad input after reading %u values\n", n);
        printf("Average of %u values is %f.\n",n (n == 0) ? 0.0 : (double) sum / n);
  
}



4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
University of Hawaii at Manoa, Honollulu (HI), Oahu(Hawaii), Tep Dobry, EE160 EE 160: Lab 10

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

Moderator's Comments:
Mod Comment edit by bakunin: please use CODE-Tags when posting code, terminal output or something such. Thank you.

Last edited by bakunin; 04-06-2011 at 03:43 PM..
 

4 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Rules for Homework & Coursework Questions Forum

Homework Help: On Posting Questions: Any and all high school and undergraduate homework assignments or textbook style exercises for which you are seeking assistance are to be posted only in our Homework & Coursework Questions area--not in blogs, visitor messages, PMs, or the main technical... (0 Replies)
Discussion started by: Neo
0 Replies

2. Homework & Coursework Questions

Community Spirit and Ethos on Homework & Coursework

Helping students is in line with the "community spirit" ethos of The UNIX and Linux Forums which aims to give free help and advice in order to support the personal and professional development of others. We encourage students to think carefully about what they do, and do not, understand about... (0 Replies)
Discussion started by: Neo
0 Replies

3. Homework & Coursework Questions

Can anybody help me with coursework

This is the coursework, in Technical University Sofia, Bulgaria prof. Koshmarov, sorry but the link to the course is broken. And this is the condition: 1. If the value of x is 5, and you have been set a new value as such x="expr $x + 10", What would be the value of x? What... (1 Reply)
Discussion started by: astralito
1 Replies

4. Post Here to Contact Site Administrators and Moderators

About Rules for Homework & Coursework Questions Forum

Hi, in my case, I have a question for topics that are slightly dealt with in class, which I am investigating on my own but which are not directly related to the lessons. Do I have to put the name of the school and others? (I can't put the name of the professor because is against the school rules... (2 Replies)
Discussion started by: Naky
2 Replies
All times are GMT -4. The time now is 07:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy