Hi, I'm a newbie to C++ so please be patient. I have to create program that outputs a simple moire pattern or a graph of y-values from a .csv file depending on which one is called. The code below is what I have before main and is where I am getting my errors,

#include <cstdlib>
#include <iostream>
#include "graphics.h"
#include <math.h>
#include <fstream>

using namespace std;

#define SCREENX 800
#define SCREENY 600
#define CENTERX 400
#define CENTERY 300
       
void moire()
{ 
    initwindow(SCREENX,SCREENY);         // Open the graphics window
    moveto(CENTERX,CENTERY);
    
    float step = M_PI/150;
    float rad;
    
    for (rad=0; rad<2*M_PI; rad+=step) 
    { 
        lineto(CENTERX,CENTERY);
        float SIZE = 300;
        lineto(CENTERX+(SIZE*sin(rad)),CENTERY+(SIZE*cos(rad)));
    }
    while(!kbhit());         //wait for user to press a key
    closegraph();            // Close the graphics window
}


void graph_file ( const char* filename )
{    
     int count;
     float yVal [1025];                 // float to store incoming y-values 
     ifstream newFile ;                 // make an object of the input file stream class
     newFile.open (filename, ifstream::in);           // open the file
     if (newFile.good())                     // if file was opened…
     {   
         while (!newFile.eof()) {            // read until end of file (eof)
               for(int n = 0; n<1024; n++)
               {
                  newFile >> yVal [n];
                  count++;          // store floats to yVal 
               }    

               if (newFile.good()) 
               {                    // print it if valid
                  for (int z = 0; z<count; z++)
                  {
                       cout << "READ: " << yVal[z] << endl;
                   }
               }
          }
   newFile.close();
   } else cerr << "File not found.\n";

I know its messy and incomplete, so far I just want to print out the values for the graph_file function just to check that my reading and placing of variables in an array is correct as I have never done that before. However my problem doesn't seem to be there, the errors I receive are as follows:
[Linker error] undefined reference to `initwindow'
[Linker error] undefined reference to `moveto'
[Linker error] undefined reference to `lineto'
[Linker error] undefined reference to `lineto'
[Linker error] undefined reference to `closegraph'
[Linker error] undefined reference to `closegraph'
ld returned 1 exit status
E:\Graph\fr\Makefile.win [Build Error] [Project1.exe] Error 1

Please can someone help, I've searched linker errors and all the answers point to the library files but I think I have everything in order?? Could you also comment on how I chose to read numbers from the .csv file and if I'm doing the right thing?? We are expected to graph to a maximum of 1024 values. The graphing bit I should be able to do later. Oh and I'm using Dev C++ 4.9.9.2

Many thanks in advance!

Have you specified -lbgi -lgdi32 -luser32 as extra libraries?

No I haven't, how do I do that?

Ah, googled those and found out what to do! now I get these errors (getting better :-) )
cannot find -lbgi
ld returned 1 exit status
C:\Documents and Settings\Student\Desktop\GraphIT Final\Makefile.win [Build Error] [GraphIT.exe] Error 1

Try and include full file path and try making a new file and type:

#include <FILE PATH>
int main(void){
moire();
}

Note that you will need to replace FILE PATH with the file path of your file

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.