syntax help!!!!!!

This is a discussion on syntax help!!!!!! within the C Programming forums, part of the General Programming Boards category; Okay before I begin let me make this disclaimer: I'm a complete noob at programming and just started C a ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    2

    Unhappy syntax help!!!!!!

    Okay before I begin let me make this disclaimer: I'm a complete noob at programming and just started C a month ago so please don't let my ignorance irritate you.

    Okay, I'm writing a program that asks a user to enter any random temperatures 26 times until the control loop variable is met. Once it is the program returns a printf that displays the avg. temp and the number of cold, hot, and warm days according to range of 60-=cold, 60-84= warm, and 85+=hot.

    Now with what I have so far I believe I have everything to get the avg. part calculated but when I go to compile I get 2 undefined reference errors for the functions "get_value", and "calculate_and_print". But aren't these syntactically correct functions?

    And if someone can be so kind to just summarize how I should go about writing the portion to calculate and return the number of hot, cold, and warm days I really appreciate it. I'm not looking for someone to write it, but merely to provide me with some instructions I can understand unlike my text. Below is what have so far and thanks for any and all insight! .............

    Code:
    /* A program to collect, calculate, and return the daily average of hot, 
       pleasant, and cold days
       Written by: Bryan Jones
       Febuary 22, 2008
    */
    
    #include <stdio.h>
    
    
    int get_n(void);
    void calculate_and_print(int n);
    double get_value(void);
    
    int main(void)
    {   int n;
        n=get_n();
        calculate_and_print(n);
        return 0;
    }
    
    int get_n(void)
    
    
    {   
        int n;
        printf("What is the total of numbers to be entered?");
        scanf("%d", &n);
        return n;
    }
    
    void calculate(int n)
    
    {
    
        double sum, average;
        int i;
        sum=0.0; 
    for (i=1; i<=n; i++) 
        sum=sum+get_value();
        average=sum/(double)(n);
        printf("The average temperature is %lf\n\n",n, average);
        return;
    }

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    [Note to regulars: topic history.]
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    2
    Quote Originally Posted by Dave_Sinkula View Post
    [Note to regulars: topic history.]
    So seeking advice from more than one resource is in some way unethical?

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by 12oclock View Post
    So seeking advice from more than one resource is in some way unethical?
    Not at all. But I can't think of anything to say that wasn't said on that thread, so why say it, except to practice my ultra-sarcasm tags?

  5. #5
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,655
    As per the other thread, you have prototyped two of your functions as:
    Code:
    void calculate_and_print(int n);
    double get_value(void);
    but you have not defined one of the prototyped functions and defined the other as:
    Code:
    void calculate(int n)
    See the problem/difference?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 09:26 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM

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