(shouting)

The Thread for Programming

here's a good place for FRIENDLY, ENJOYABLE, and otherwise very GENERAL discussion!
devil†zukin

Re: The Thread for Programming

Post by devil†zukin »

Frozelar wrote:So uh, is there a way to get pseudo-random numbers that change more often than every second? Like say, every frame in a 60fps game? I'm trying to make a particle engine in which the particles that spawn move in random directions, by the way.

As it stands, I'm using

Code: Select all

srand(time(NULL));
but as I hinted at, if I do that, then all the particles that spawn will move in exactly the same direction for each second, which is kind of awkward.

I'm sure I could figure out something unrelated to random numbers for getting it working, but I figured it would be more neat if it could be entirely random. I was thinking maybe I could have a counter that increments each frame, and use that to somehow influence the randomness? I dunno.

Thanks in advance!
it sounds like you're doing it every frame

you only need to do it once, otherwise you will constantly reset the random number generator to the seed you get from time(NULL)

that's probably why you're getting the same results from second to second

[to clarify you should srand() once and then just call rand() every time you need random numbers]

e: if you're using c++, c++11 now has random number features -> http://www.open-std.org/jtc1/sc22/wg21/ ... /n3551.pdf which are a lot more flexible and have specific requirements
User avatar
Ashan
The world has become a place
Posts: 2802
Joined: 14 years ago
Location: Canada
https://ashan.talkhaus.com/

Re: The Thread for Programming

Post by Ashan »

Oh yeah, for an assignment once I was trying to do a thing where it would roll 2 dice and it kept giving me the same 2 numbers. It was the same thing, I had a function that would return a random number between 1 and 6 and it took me forever before I figured out it was because I was seeding the RNG in the function rather than once at the beginning. It makes sense I guess cause it does the calculations so fast, the time would basically be the same time the first go through the function compared to the second time.
Image
Image
Image
Image
Image
Image
Frozelar
Retired Screamer
Posts: 5
Joined: 12 years ago
Location: The Place You Wish You Were

Re: The Thread for Programming

Post by Frozelar »

RenaBeach wrote:you only need to do it once, otherwise you will constantly reset the random number generator to the seed you get from time(NULL)
[...]
e: if you're using c++, c++11 now has random number features -> http://www.open-std.org/jtc1/sc22/wg21/ ... /n3551.pdf which are a lot more flexible and have specific requirements
Oh. I thought it was better to seed it every time but now I see how little sense that makes.
And man, c++11 just has everything doesn't it?!

Thank you Rena!
devil†zukin

Re: The Thread for Programming

Post by devil†zukin »

time() usually only has a 1 second precision so it's not very hard
Frozelar wrote: And man, c++11 just has everything doesn't it?!
yeah it's really like a new language
devil†zukin

Re: The Thread for Programming

Post by devil†zukin »

Frozelar wrote: Oh. I thought it was better to seed it every time but now I see how little sense that makes.!
i think u got it but for anybody else reading this, you only generally need to seed it once _per application run_ to get useful, new random numbers (you can also reseed it any time you want a reproducible sequence of random numbers i.e. like when levels are generated in minecraft)

if you don't seed it at all it'll probably just have a default seed (for all implementations i've seen that has been 0) and as a result you'll likely just get the same sequence of numbers every time you run the application, hence why the current time is commonly used as a seed
User avatar
Hoeloe
A2XT person
Posts: 1016
Joined: 12 years ago
Pronouns: she/her
Location: Spaaace

Re: The Thread for Programming

Post by Hoeloe »

RenaBeach wrote:
Frozelar wrote: Oh. I thought it was better to seed it every time but now I see how little sense that makes.!
i think u got it but for anybody else reading this, you only generally need to seed it once _per application run_ to get useful, new random numbers (you can also reseed it any time you want a reproducible sequence of random numbers i.e. like when levels are generated in minecraft)

if you don't seed it at all it'll probably just have a default seed (for all implementations i've seen that has been 0) and as a result you'll likely just get the same sequence of numbers every time you run the application, hence why the current time is commonly used as a seed
It's worth remembering how RNGs actually work, for those who don't know. They aren't truly random, they're just a function that provide a number sequence that appears roughly random. The seed for an RNG is used as part of the calculation of the sequence, allowing a different seed to produce a different pseudo-random sequence. By re-seeding with the same seed each time, it produces the same sequence, and if you're using a time variable, those usually only update once per tick, meaning all calls to the time function within the same tick will return the same value, and thus the same seed.

So yes, the best solution is to seed once at the start of the application (inserting a seed such as time here is usually a good idea, as the time will be slightly different on each run of the application), and then just follow the sequence.
Image
Image
Image
Image
Image
User avatar
Ashan
The world has become a place
Posts: 2802
Joined: 14 years ago
Location: Canada
https://ashan.talkhaus.com/

Re: The Thread for Programming

Post by Ashan »

So my CS 201 class is kind of scaring the hell out of me.

It's digital systems and information and the classes are 3 hours long and are taught by a guy who doesn't explain things, is super quiet and hard to understand, and the classes are 3 hours long so by the time the first hour passes I'm already zoned out completely.
From the first class I was already lost and it's probably only going to get worse from here unless I can figure this stuff out on my own I guess.

I barely know what it's about. There's been stuff on binary, parity bits, Gray code, etc. and I have no idea what I need to be catching up on between classes cause I'm sure not learning anything in the classes.
Image
Image
Image
Image
Image
Image
User avatar
Ashan
The world has become a place
Posts: 2802
Joined: 14 years ago
Location: Canada
https://ashan.talkhaus.com/

Re: The Thread for Programming

Post by Ashan »

I need a way to get a string, and check if it's a valid double, so I can parse it into a double and use it but I don't know a good way to check if it's a valid double.
Image
Image
Image
Image
Image
Image
User avatar
WhattayaBrian
Posts: 239
Joined: 9 years ago

Re: The Thread for Programming

Post by WhattayaBrian »

What language?
If you read this post and thought "Wow, what a swell guy, I sure would like to hear his voice and also watch videogames?" then do I have a link for you.

Current Game: Distorted Travesty 3
User avatar
Ashan
The world has become a place
Posts: 2802
Joined: 14 years ago
Location: Canada
https://ashan.talkhaus.com/

Re: The Thread for Programming

Post by Ashan »

Sorry, C++. And I should take a step back cause I might be overcomplicating this.
Basically for the question I need to make a calculator that starts at 0 and takes in operations in the fomat:
[operator] [number]
for example:
+ 3.8
/ 4.5
So I know how to take in the operator and make sure it's a valid operator and whatnot (for the sake of this, it's +, -, *, /, and ^), but I don't know how to make sure that the second value being taken in is a double. Like, to make sure the first character is one of the operators, I just make a function that compares it to make sure it's one of them and returns true if it is, but for the second value I don't know how to make sure it's a number. I'll just being doing:
std::cin >> oprtr >> givenValue;
to get the operator and value, respectively, I just need to make sure that givenValue is a number before doing anything with it because I need to give an error if an invalid input is given. So in that line there, oprtr would be a char, but if I make givenValue a double it would mess everything up if the user inputs a bunch of random characters, so I was thinking I need to make it a string and then check if the string is a double, and if it is I would convert it into double... or something
Image
Image
Image
Image
Image
Image
User avatar
WhattayaBrian
Posts: 239
Joined: 9 years ago

Re: The Thread for Programming

Post by WhattayaBrian »

Input's really hard to do right. It's one of the hardest things in programming to do right. Isn't it funny that it's used so much for beginner lessons?

std::cin is a std::istream, which means it has two member functions you're interested in: good() and fail(). These check the state of the istream (in subtly different ways). It also overloads an implicit conversion to bool, which is equivalent to !fail().

An example:

Code: Select all

char op;
double value;

std::cin >> op >> value;
if(!std::cin)
{
    std::cout << "You stupid crapper monkey.\n";
}
If you want to continue asking for input, you'll need to call std::cin.clear() to reset the error state.
If you read this post and thought "Wow, what a swell guy, I sure would like to hear his voice and also watch videogames?" then do I have a link for you.

Current Game: Distorted Travesty 3
Zha Hong Lang
"HTMI - Hyper Text Markup Interface"
Posts: 1496
Joined: 10 years ago
First name: ZHL
Pronouns: Male
Location: United States of America

Re: The Thread for Programming

Post by Zha Hong Lang »

I remember the old days when I used to mess around in Libertybasic


I've gained enough knowledge in web markups that I can usually understand what something does by looking at its code, although javascript may be a bit harder for me. Before, I had freelanced around with ruby and python, (while simultaneously trying to see how a programming language worked) though ruby seemed very weird to find how to input and I got tired of python really quickly because I had literally no motivation backing me up.

Now, I'm learning how to use rails with AWDwR4 as a guideline. So far I've liked it, the book also happened to explain the fact that general work is not done in shell or in a pre-installed (or otherwise obtained) official IDE, which every web tutorial for ruby I'd seen before had failed to mention. Currently I write stuff in Notepad++, which I haven't had trouble with yet, so I may keep using it for a while.

I only really want to use Ruby for Rails, though, because I would rather C# or C++ for when I want to start serious application programming. (would anybody happen to tell me which C would be better for what situation or something like that? I've had pretty prejudiced answers before, so it'd be nice to have a more informative answer than a one word kind)
Last edited by Zha Hong Lang 9 years ago, edited 1 time in total.
(Formerly Jayoshi)
User avatar
Wohlstand
Moondust and TheXTech developer
Posts: 186
Joined: 10 years ago
First name: Vitaly
Pronouns: he/him/his
Location: Moscow, Russia

Re: The Thread for Programming

Post by Wohlstand »

WhattayaBrian wrote:Input's really hard to do right. It's one of the hardest things in programming to do right. Isn't it funny that it's used so much for beginner lessons?

std::cin is a std::istream, which means it has two member functions you're interested in: good() and fail(). These check the state of the istream (in subtly different ways). It also overloads an implicit conversion to bool, which is equivalent to !fail().

An example:

Code: Select all

char op;
double value;

std::cin >> op >> value;
if(!std::cin)
{
    std::cout << "You stupid crapper monkey.\n";
}
If you want to continue asking for input, you'll need to call std::cin.clear() to reset the error state.
I have another protector for this thing, but it have more code for this.

Code: Select all

double value;
char op;
std::string tmp;

retrychar:
std::cout <<"type one char:\n":
std::cin >> tmp;
if(tmp.size()!=1)
{
   std::cout << "Wrong number of characters! type only one!\n"; goto retrychar;
}
op = tmp[0];

std::cout <<"Now type floading point number:\n":
retrydouble:
std::cin >> tmp;
bool dot=false;
for(int i=0;i<tmp.size();i++) //If you wish have less code - use regex, but this manual check works too
{ // I think, this thing should be as function "double StrToDouble(std::string, bool*ok=NULL)" which return 0.0 if wrong value
     if(!isdegit(tmp[i]))
     {
           if((i==0)&&(tmp[i]=='-'))
               continue;
           else
           if((tmp[i]=='.')&&(!dot))
           {
               dot=true;
               continue;
           }
           else
           {
               std::cout << "Wrong value, should be floating point! Try again!\n"; goto retrydouble;
           }
     }
}
sscanf(tmp.c_str(), "%d", value);
But way with using of cin.fail() and cin.clear() is esier and more safer, works with MinGW 4.8 / 4.9 and GCC on Linux. On Visual Studio (tested on 2010) this thing is works incorrectly. Therefore my big code should have more stability with almost any creepy compilers like MSVC, but my choice are MinGW and GCC.
User avatar
WhattayaBrian
Posts: 239
Joined: 9 years ago

Re: The Thread for Programming

Post by WhattayaBrian »

Can you say what didn't work for you? Because, unless I typed something wrong, this is very standards compliant, essentially boilerplate code.
If you read this post and thought "Wow, what a swell guy, I sure would like to hear his voice and also watch videogames?" then do I have a link for you.

Current Game: Distorted Travesty 3
User avatar
Wohlstand
Moondust and TheXTech developer
Posts: 186
Joined: 10 years ago
First name: Vitaly
Pronouns: he/him/his
Location: Moscow, Russia

Re: The Thread for Programming

Post by Wohlstand »

WhattayaBrian wrote:Can you say what didn't work for you? Because, unless I typed something wrong, this is very standards compliant, essentially boilerplate code.
Oh, I just made little test, and got true results:

Reasons, why std::cin will works wrongly: if you will type wrong characters after degits (for example 578gwr will cause error)
if you will type "g542", the "fail()" will works.

Testing code:

Code: Select all

#include <iostream>

int main()
{
	double test;
	std::cout<<"First cin!\n";
	std::cin >> test;
	if(std::cin.fail())
		std::cout<<"You sucks!\n";
	else
		std::cout<<"Yur text is\n"<<test;
	std::cin.clear();

	std::cout<<"Second cin!\n";
	std::cin >> test;

	std::cin.clear();
	std::cout<<"Third cin!\n";
	std::cin >> test;

	return 0;
}
and result (MinGW Windows):

Code: Select all

T:\root\cpp>g++ dummy.cpp -o dummy.exe

T:\root\cpp>dummy
First cin!
24gh
Yur text is
24Second cin!
Third cin!

T:\root\cpp>
result (GCC Linux)

Code: Select all

[root@whl-sr-001 cpp]# g++ dummy.cpp -o dummy
[root@whl-sr-001 cpp]# ./dummy
First cin!
466.57
Yur text is                  
466.57Second cin!       //Accepted, value is right
45/234^H^H^H        
Third cin!                   //Hey! this should be wrong!, stinky cin!
			          //third cin skipped by broken cin
[root@whl-sr-001 cpp]# ./dummy
First cin!
24f
Yur text is              //Hey! this should be wrong!, stinky cin!
24Second cin!        //skipped by broken cin
Third cin!             //skipped by broken cin again
[root@whl-sr-001 cpp]# 

Anyway, this will work stable:

Code: Select all

#include <iostream>
#include <stdio.h>
#include <string.h>

double StrToDouble(std::string in, bool*ok=NULL)
{
	if(in.empty())
	{
               	if(ok) *ok=true;
		return 0.0;
	}

	double value;
	bool dot=false;
	for(int i=0;i<in.size();i++) //If you wish have less code - use regex, but this manual check works too
	{
	     if(!isdigit(in[i]))
	     {
	           if((i==0)&&((in[i]=='-')||(in[i]=='+')))
	               continue;
	           else
	           if((in[i]=='.')&&(!dot))
	           {
	               dot=true;
	               continue;
	           }
	           else
	           {
	               	if(ok) *ok=false;
			return 0.0;
	           }
	     }
	}
	sscanf(in.c_str(), "%lf", &value);
	if(ok) *ok=true;
	return value;	
}

int main()
{
	double value=0;
	char op;
	std::string tmp;
	
	retrychar:
	tmp.clear();
	std::cout <<"type one char:\n";
	std::cin >> tmp;
	if(tmp.size()!=1)
	{
	   std::cout << "Wrong number of characters! type only one!\n"; goto retrychar;
	}
	op = tmp[0];
	std::cout << "You typed character '"<< op <<"'\n\n";

	
	std::cout <<"Now type floading point number:\n";
	retrydouble:
	tmp.clear();
	std::cin >> tmp;
	bool ok=false;
	value = StrToDouble(tmp, &ok);
	if(!ok)
	{
		std::cout<<"Wrong value, should be floating point! Try again!\n";
		goto retrydouble;
	}

	std::cout << "You typed string '"<< tmp <<"'\n\n";

	std::cout << "You typed number '"<< value <<"', hm, I forgot to use the iomanip.h, but anyway\n";
	printf("with printf I can manupulate without 'iomanip.h'! :D, enjoy: %.8lf\n\n", value);

	return 0;
}
this thing always sends a string data and cin will never crashed and you will anyway have able to type any values
User avatar
Ashan
The world has become a place
Posts: 2802
Joined: 14 years ago
Location: Canada
https://ashan.talkhaus.com/

Re: The Thread for Programming

Post by Ashan »

WhattayaBrian wrote:Input's really hard to do right. It's one of the hardest things in programming to do right. Isn't it funny that it's used so much for beginner lessons?

std::cin is a std::istream, which means it has two member functions you're interested in: good() and fail(). These check the state of the istream (in subtly different ways). It also overloads an implicit conversion to bool, which is equivalent to !fail().

An example:

Code: Select all

char op;
double value;

std::cin >> op >> value;
if(!std::cin)
{
    std::cout << "You stupid crapper monkey.\n";
}
If you want to continue asking for input, you'll need to call std::cin.clear() to reset the error state.
Okay, yeah. I mean this is what I have so far (it's mostly unfinished and uncommented so be warned):
http://pastebin.com/LV8Cqyyn
so I'll need to run a check for !std::cin every time, and then clear it I guess? I'm a little confused on how that works.
(also yeah I know I'm using namespace std at the top there and I'm not supposed to but meh)
Image
Image
Image
Image
Image
Image
User avatar
Wohlstand
Moondust and TheXTech developer
Posts: 186
Joined: 10 years ago
First name: Vitaly
Pronouns: he/him/his
Location: Moscow, Russia

Re: The Thread for Programming

Post by Wohlstand »

Ashan wrote:
WhattayaBrian wrote:Input's really hard to do right. It's one of the hardest things in programming to do right. Isn't it funny that it's used so much for beginner lessons?

std::cin is a std::istream, which means it has two member functions you're interested in: good() and fail(). These check the state of the istream (in subtly different ways). It also overloads an implicit conversion to bool, which is equivalent to !fail().

An example:

Code: Select all

char op;
double value;

std::cin >> op >> value;
if(!std::cin)
{
    std::cout << "You stupid crapper monkey.\n";
}
If you want to continue asking for input, you'll need to call std::cin.clear() to reset the error state.
Okay, yeah. I mean this is what I have so far (it's mostly unfinished and uncommented so be warned):
http://pastebin.com/LV8Cqyyn
so I'll need to run a check for !std::cin every time, and then clear it I guess? I'm a little confused on how that works.
(also yeah I know I'm using namespace std at the top there and I'm not supposed to but meh)
Be careful!:
if you will type "56fw" for example, even after cin.clean() you will have no able to restore able use them again.
Therefore I used middle string buffer and validated it manually. Try it ;)
This protector will work correctly if you will type "fg572" (first characters are letters!), but if you was typed "57fg2" (first characters are degits!) you will have no able to restore usable of cin! (I was tested it)

Code: Select all

	double test;
	std::cout<<"First cin!\n";
	std::cin >> test;
	if(!std::cin)
		std::cout<<"You sucks!\n";
	else
		std::cout<<"Yur text is\n"<<test;
	std::cin.clear();

	std::cout<<"Second cin!\n";
	std::cin >> test;
	if(!std::cin)
		std::cout<<"fail!\n";

	std::cin.clear();
	std::cout<<"Third cin!\n";
	std::cin >> test;
	if(!std::cin)
		std::cout<<"fail!\n";

Code: Select all

[root@whl-sr-001 cpp]# g++ dummy.cpp -o dummy
[root@whl-sr-001 cpp]# ./dummy
First cin!
-4f.24y2
Yur text is
-4Second cin!
fail!
Third cin!
fail!
[root@whl-sr-001 cpp]# 
User avatar
Ashan
The world has become a place
Posts: 2802
Joined: 14 years ago
Location: Canada
https://ashan.talkhaus.com/

Re: The Thread for Programming

Post by Ashan »

Man I sure love using CC it's great
ah.png
ah.png (60.35 KiB) Viewed 4549 times
Here's my source code, I have no idea why CC hates it so much, it works fine in both Xcode and Visual Studio (although I just found out that it freaks out if you only put in 1 or 2 characters as input in Visual Studio)
http://pastebin.com/LVVCQWJh

edit: also I just realized how silly it is that I made a function called "isNotZero" that runs 1 line that could be written out as easily as it is to call a function.
Image
Image
Image
Image
Image
Image
User avatar
Wohlstand
Moondust and TheXTech developer
Posts: 186
Joined: 10 years ago
First name: Vitaly
Pronouns: he/him/his
Location: Moscow, Russia

Re: The Thread for Programming

Post by Wohlstand »

Ashan wrote:Man I sure love using CC it's great
ah.png
Here's my source code, I have no idea why CC hates it so much, it works fine in both Xcode and Visual Studio (although I just found out that it freaks out if you only put in 1 or 2 characters as input in Visual Studio)
http://pastebin.com/LVVCQWJh

edit: also I just realized how silly it is that I made a function called "isNotZero" that runs 1 line that could be written out as easily as it is to call a function.
Hey, build it with "g++":

Code: Select all

g++ exercise1.cpp -o exercise1
I built it successfully. "cc" or "gcc" just for C but no C++
User avatar
Ashan
The world has become a place
Posts: 2802
Joined: 14 years ago
Location: Canada
https://ashan.talkhaus.com/

Re: The Thread for Programming

Post by Ashan »

Well we were specifically told to make sure it runs in CC so I don't know what
We use g++ in the lab for the class, but regardless, that's not seeming to work for me either. I don't know why it doesn't work, cause I can access the little things I made during the lab, and compile them fine, but it's not working for me when I try to make a file from home.
I'm curious if it's how I'm making the file? In the lab we were using emacs, and here I'm just using pico so maybe it doesn't like files that were made in pico? I don't know
Image
Image
Image
Image
Image
Image
User avatar
Wohlstand
Moondust and TheXTech developer
Posts: 186
Joined: 10 years ago
First name: Vitaly
Pronouns: he/him/his
Location: Moscow, Russia

Re: The Thread for Programming

Post by Wohlstand »

Ashan wrote:Well we were specifically told to make sure it runs in CC so I don't know what
We use g++ in the lab for the class, but regardless, that's not seeming to work for me either. I don't know why it doesn't work, cause I can access the little things I made during the lab, and compile them fine, but it's not working for me when I try to make a file from home.
I'm curious if it's how I'm making the file? In the lab we were using emacs, and here I'm just using pico so maybe it doesn't like files that were made in pico? I don't know
Which distro/os you have?
Debian/Ubuntu/Mint: apt-get install gcc g++
Redhat/CentOS/Fedora: yum install gcc g++
openSUSE: zypper install gcc g++
Arch: pacman install gcc g++
MacOS: http://www-scf.usc.edu/~csci104/install ... ccmac.html
Windows: http://www.mingw.org/ or with able to use Win64: http://mingw-w64.sourceforge.net/index.php
FreeBSD: http://stackoverflow.com/questions/2318 ... on-freebsd

You can use any text editor (nano, pico, vim, mcedit, etc.)
User avatar
FlockOfWingedDoors
Rolling Initiative...
Posts: 0
Joined: 9 years ago

Re: The Thread for Programming

Post by FlockOfWingedDoors »

School intro'd me to programming with stuff like Flash, Turing and VB. I started dabbling with HTML, CSS, PHP and JavaScript on my own for a while. Also took Python for a spin.

Later I took some Java courses and it's my goto, even though a uni VB course got me more proficient at that too.
It's easier than 2by2 matrix multiplication.
User avatar
Ashan
The world has become a place
Posts: 2802
Joined: 14 years ago
Location: Canada
https://ashan.talkhaus.com/

Re: The Thread for Programming

Post by Ashan »

I made a calendar thing for an assignment. I typed it out at 3 in the morning and made some fixes today.
https://github.com/Ashanmaril/Calendar
I'm not super happy with the stupid "goodDate" boolean and "isGoodDate()" stuff, but it's there for the sake of what was expected in the question. I don't know if there was a better way I should have done that but I was kind of playing by ear and that's what it turned into.

Also I'm salty cause in the toString() function I originally was using to_string() to add integers to the string that's put together throughout the run of the function, but then I tried it out with CC and g++ and found out to_string() didn't work (it might have been added in C++11 or something?) so I had to change that stuff to a stringstream and make it uglier. :(
Image
Image
Image
Image
Image
Image
devil†zukin

Re: The Thread for Programming

Post by devil†zukin »

Ashan wrote:I made a calendar thing for an assignment. I typed it out at 3 in the morning and made some fixes today.
https://github.com/Ashanmaril/Calendar
I'm not super happy with the stupid "goodDate" boolean and "isGoodDate()" stuff, but it's there for the sake of what was expected in the question. I don't know if there was a better way I should have done that but I was kind of playing by ear and that's what it turned into.

Also I'm salty cause in the toString() function I originally was using to_string() to add integers to the string that's put together throughout the run of the function, but then I tried it out with CC and g++ and found out to_string() didn't work (it might have been added in C++11 or something?) so I had to change that stuff to a stringstream and make it uglier. :(
did u try -std=c++11
User avatar
Wohlstand
Moondust and TheXTech developer
Posts: 186
Joined: 10 years ago
First name: Vitaly
Pronouns: he/him/his
Location: Moscow, Russia

Re: The Thread for Programming

Post by Wohlstand »

Ashan wrote:I made a calendar thing for an assignment. I typed it out at 3 in the morning and made some fixes today.
https://github.com/Ashanmaril/Calendar
I'm not super happy with the stupid "goodDate" boolean and "isGoodDate()" stuff, but it's there for the sake of what was expected in the question. I don't know if there was a better way I should have done that but I was kind of playing by ear and that's what it turned into.

Also I'm salty cause in the toString() function I originally was using to_string() to add integers to the string that's put together throughout the run of the function, but then I tried it out with CC and g++ and found out to_string() didn't work (it might have been added in C++11 or something?) so I had to change that stuff to a stringstream and make it uglier. :(
Use this function:

Code: Select all

#include <sstream>
#include <string>

std::string my_to_string(int x)
{
  std::stringstream o;
  o << x;
  return o.str();
}

//make also functions for long, float and double
Post Reply