Page 1 of 3 123 LastLast
Results 1 to 10 of 21
  1. #1

    Default C program help...Again?


    Hello my fellow programmers!

    Naa napud ko diri because I'm in need of help about my program. Our instructor gave us this problem:

    "Write a C program that stores the weight of babies in kilograms. The number of babies depends on the user input. Your program must also do the following;
    - First, to compute & display for the average weight
    - Second, to display only those babies born with normal weight (weight more than 2.3 kilos)
    Format: Baby[index] = <weight>
    - Third, to display the weight of the baby with the heaviest weight
    - Fourth, to display the weight of the baby with the lightest weight
    - Lastly, sort the list of weights in ascending order"

    Then, ana among instructor nga mugamit ug functions to perform the tasks, then kato pud nga "dynamicially assign your array in the heap" - meaning katong malloc()/calloc() ug gamit sad daw mi sa sorting algorithms nga gihatag niya.

    I already made a C program regarding this question. After compiling then running it, ning output siya ug "scanf : floating point not linked"... Please help me!

    Here's my code:
    Code:
    #include<stdio.h>
    #include<conio.h>
    #include<stdlib.h>
    
    int size(void);
    float *input(int n);
    void average(float [], int n);
    void normal(float [], int n);
    void heaviest(float [], int n);
    void lightest(float [], int n);
    void insertion_sort(float [], int n);
    
    void main(void)
    {
     float *a;
     int n;
     clrscr();
    
     n = size();
     a = input(n);
     average(a, n);
     normal(a, n);
     heaviest(a, n);
     lightest(a, n);
     insertion_sort(a, n);
    
     getch();
    }
    int size(void)
    {
     int n;
     printf("Enter number of babies: ");
     scanf("%d", &n);
     return n;
    }
    float *input(int n)
    {
     float *a;
     int i;
    
     a = (float *) malloc (sizeof(float) * n);
    
     if (a != NULL)
     {
      printf("Enter weight of the %d babies in kilograms: ", n);
      for (i=0;i<n;i++)
       scanf("%f", &a[i]);
     }
    
     return a;
    }
    void average(float a[], int n)
    {
     int i;
     float sum=0, ave;
    
     for (i=0;i<n;i++)
      sum+=a[i];
    
     ave = sum / n;
    
     printf("Average weight: %.1f\n", ave);
    }
    void normal(float a[], int n)
    {
     int i;
    
     printf("Normal Babies:\n");
     for (i=0;i<n;i++)
      if (a[i] > 2.3)
       printf("Baby[%d] = %.1f\n", i, a[i]);
    }
    void heaviest(float a[], int n)
    {
     int i;
     float heaviest;
    
     heaviest=a[0];
     for (i=1;i<n;i++)
      heaviest=(a[i]>heaviest)?a[i]:heaviest;
    
     printf("Heaviest weight: %.1f\n", heaviest);
    }
    void lightest(float a[], int n)
    {
     int i;
     float lightest;
    
     lightest=a[0];
     for (i=1;i<n;i++)
      lightest=(a[i]<lightest)?a[i]:lightest;
    
     printf("Lightest weight: %.1f\n", lightest);
    }
    void insertion_sort(float a[], int n)
    {
     int i, j, temp;
     for (i=1;i<n;i++)
     {
      temp=a[i];
      j=i;
      while ((j>0) && (a[j-1]>temp))
      {
       a[j] = a[j-1];
       j--;
      }
      a[j]=temp;
     }
     printf("Sorted weights in ascending order:\n");
    
     for (i=0;i<n;i++)
      printf("Baby[%d] = %f\n", i, a[i]);
    }
    Check lang ko ani nga thread nako time to time until tomorrow because inig Monday nani namo i-submit ang final written output. Thank you kaayo ninyo guys!

  2. #2
    maayo naman ka c brad... keep up the good work...

    i would like to help you but, i am very rusty sa C/C++.. sorry..

  3. #3
    Aw, ok ra bro! Maybe you might be able to help me out next time

  4. #4
    The program looks fine. Basin ang problema naa sa compiler settings. Turbo C imong gigamit na compiler? I-pass na lang na diretso sa imo teacher.

  5. #5
    Searching for the terms "scanf : floating point not linked" in google returned this and this.

  6. #6
    ok raman cya bai, naa cguro prob sa imo compiler...pero i think na submit nani nnyo hehe...

    OT:
    taga USC ka no? :P

  7. #7
    ga problema pa ka ani? unsa ide nimo gamit ani? nya wat line nag error?

  8. #8
    the error has something to do with teh ide, im guessing, TC..

    my usual solution, is to it the long way
    instead of:
    scanf("%f", &a[i]);

    do:

    float f; /* some var */
    scanf("%f", &f);
    a[i] = f;

    *** or use a double precision variable instead.

  9. #9
    Dump Turbo C and use a modern C compiler.

  10. #10
    Quote Originally Posted by doomsweek View Post
    Dump Turbo C and use a modern C compiler.
    i don't quite agree. TC is fairly good at "small programs". "modern" C compilers have teh bloat. i say, have both.

  11.    Advertisement

Page 1 of 3 123 LastLast

Similar Threads

 
  1. Help Again! My C Program not giving the desired output
    By marcdaven in forum Programming
    Replies: 7
    Last Post: 02-23-2010, 08:06 AM
  2. HOW TO MAKE 'YAHOO BOOTER PROGRAM' HELP
    By jdbebz in forum Software & Games (Old)
    Replies: 6
    Last Post: 02-12-2008, 12:45 PM
  3. VB6 programming help??
    By dhuDz in forum Programming
    Replies: 6
    Last Post: 10-12-2007, 12:50 PM
  4. Java programming help pls...
    By mr_gwen in forum Programming
    Replies: 6
    Last Post: 11-03-2006, 12:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top