Here are my files I have so far and here is my intent w/them. I am currently taking a c programming course at a university. I am trying to create a header file and a .c file that will make a function usable in the main function. We have been instructed to do it in this format. I am trying to just get it to work and am having some problems.
What i'm trying to do w/this program. I have my main section of the program and I'm trying to call the function readValue, which reads in a number. I do this three times and then I add the numbers together in the main function and print the result.
Code:
//example.c
#include <stdio.h>
#include <stdlib.h>
#include "avg.h"
int main(int argc, char *argv[])
{
int n1, n2, n3, sum = 0;
double avg;
n1 = readValue();
n2 = readValue();
n3 = readValue();
sum = n1 + n2 + n3;
system("PAUSE");
return 0;
}
//avg.h
#ifndef AVG_H
#define AVG_H
#include<stdio.h>
int readvalue();
#endif
//avgfunction.c
#include "avg.h"
int readValue()
{
int num;
printf("please enter an int > 0");
scanf("%i", &num);
while(num <=0)
{
printf("please enter an int > 0");
scanf("%i", &num);
}
}
return num;
//error: 'undefined reference to readValue'
If anyone could help me get this to work that would be awesome. I can not for the life of me find out why. I've read online and read the book, which is using a different style for creating functions.