I'm a toal noob to programming. i just bought a C++ book and im trying to develop some very simple programs. I'm using dev C++. I'm stuck on this one, its having an issue linking. here is my code:

#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

int rand_1toN(int sides);

int main() {
    int sides, times, x, r;
    srand(time(NULL));
    while(1){
    cout<< endl << "Hello! This program will generate a random number between 1";
    cout<< endl << "and any number you specify, however many times you want.";
    cout<< endl << "Essentially rolling any sided dice you want as many times as you want.";
    cout<< endl << "Enter 0 to exit.";
    cout<< endl << "Enter the amount of sides the dice has:";
    cin>> sides;
    cout<< endl << "Enter the amount of dice want to roll:";
    cin>> times;
    if (sides == 0) 
              break;
              else
              for (x = 1; x <= times; x++) {
                  r = rand_1toN(sides);
                  cout << r << " ";
                  }
                  return 0;
                  }
                  }

here is the error message:

[Linker error] undefined reference to `rand_1toN(int)'
ld returned 1 exit status

I haventeven been able to test it so i dont even know if it will output what i want it to yet. a lot of what i have been doing is just trial and error on things that are probably obvious for a more experienced prgrammer. any help would be extremely appreciated!
thanks

Comments
We know you're a noob. You can't follow simple instructions

>undefined reference to `rand_1toN(int)'
rand_1toN isn't going to magically do something. You have to give it a definition.

As you are, new, I should rather clarify what Narue meant to say.
Look at Line 7. That is the declaration of the function (formally this is called a prototype of a function). It tells the compiler "Hey, if you get a call for this function, assume that I am written it somewhere below" Thus the compiler(actually the linker) will search you whole code to find the definition of the function. The definition tells what the function actually does.
So write the definition of rand_1toN as:

//after the line 30.
int rand_1toN(int sides)
{
//write codes of the function
}

Also, your brackets {} are misplaced, correct them.

oooohhhhhhhh. i figured it would be something considered simple and stupid. thanks.

here is my 'final' copy:

#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

int rand_1toN(int sides);

int main() {
    int sides, times, x, r;
    srand(time(NULL));
    while(1){
    cout<< endl << "Hello! This program will generate a random number between 1";
    cout<< endl << "and any number you specify, however many times you want.";
    cout<< endl << "Essentially rolling any sided dice you want as many times as you want.";
    cout<< endl << "Enter 0 to exit.";
    cout<< endl << "Enter the amount of sides the dice has:";
    cin>> sides;
                  if (sides == 0)
              break;
              else{
    cout<< endl << "Enter the amount of dice want to roll:";
    cin>> times;
              for (x = 1; x <= times; x++) {
                  r = rand_1toN(sides)+1;
                  cout << r << ", ";
                  }
              cout << endl;
              }
              }
                  return 0;
            }
                 int rand_1toN(int sides) {
                     return rand() % sides;
                  }

does everything on this look okay?
btw thank you so much for your help.

I got infractions because of not using code tags.
Learn to add code tags in the Quick Reply to Thread
box before typing anything...
I recommend that u should do tags next time...

In your program, syntactically, it is correct.

This question has already been answered. Start a new discussion instead.