so i'm trying to implement a random generating date so that everytime it is called a new random date will pop up! but it seems like everytime i run it, my program just shows the presaved memory as the variable (which should be the random number) i will post my code below! any tips would be appreciated!
// date.h
#ifndef DATE_H
#define DATE_H
#include <ctime>
#include <cstdlib>
class Date
{
private:
int day;
int month;
int year;
public:
Date(){
srand(time(NULL));
}//end Date construct
void getDate(int , int , int );
void printDate();
};
#endif
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
//date.cpp
#include "date.h"
#include <iostream>
usingnamespace std;
void Date::getDate(int day, int month, int year)
{
day = rand() % 30 + 1;
month = rand() % 11 + 1;
year = 1900 + rand() % 69 + 20;
}
void Date::printDate()
{
cout << month << '/' << day << '/' << year << endl;
}
please don't be afraid to shoot down my whole code...i'm quite a beginner :)
the number it keeps outputting as this simple date is this "100/400/2147348480" so obviously that's not the parameters that i wanted my randoms to be in lol
Also note that srand( time( NULL ) ); will generate the same sequence of random numbers if time(NULL) returns
the same value (it returns seconds, so you cannot run your program more than once per second).
it's giving me this wack error that says :error: no matching function for call to 'Date::getDate()' on the line 17 of the main...or the getDate call...???