I am trying to get a simple program to work but keep getting a LNK1561 error. What am i doing wrong here.
The main code
<
#include <iostream>
#include <fstream>
#include "average.h"
using namespace std;
int start()
{
cout << "this is to find the average of 5 numbers.";
cout << endl;
ifstream average;
cin.get();
cin.get();
return 0;
}
>
The header file
<
#include <cmath>
int avg( int average);
>
the cpp for the average
<
#include <iostream>
#include "average.h"
#include <cmath>
using namespace std;
int num[4];
int counter;
int sum;
int averages;
int avg(int average)
{
counter = 0;
while(counter <= 4);
{
cout << "enter a number ";
cin>> num[counter];
counter ++;
}
cout <<endl;
sum = 0;
for (counter = 0; counter < 4; counter ++)
sum = sum + num[counter];
averages = (sum / 5);
cout << "the average of your numbers was ";
cout << averages;
return (averages);
}
>
I could really use some help with this. Need an answer as soon as possible and it has to remain as separate files.
A linker error means the issue is not with the actual code but the files and method definitions. Post the full error and post average.h. Also, use click the <> to format your code with code tags.
#include <iostream>
#include "average.h"
#include <cmath>
usingnamespace std;
int num[4];
int counter;
int sum;
int averages;
int avg(int average)
{
counter = 0;
while(counter <= 4);
{
cout << "enter a number ";
cin>> num[counter];
counter ++;
}
cout <<endl;
sum = 0;
for (counter = 0; counter < 4; counter ++)
sum = sum + num[counter];
averages = (sum / 5);
cout << "the average of your numbers was ";
cout << averages;
return (averages);
}