• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 08:26
CET 14:26
KST 22:26
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
Behind the Blue - Team Liquid History Book7Clem wins HomeStory Cup 289HomeStory Cup 28 - Info & Preview13Rongyi Cup S3 - Preview & Info4herO wins SC2 All-Star Invitational14
Community News
PIG STY FESTIVAL 7.0! (19 Feb - 1 Mar)4Weekly Cups (Jan 26-Feb 1): herO, Clem, ByuN, Classic win2RSL Season 4 announced for March-April7Weekly Cups (Jan 19-25): Bunny, Trigger, MaxPax win3Weekly Cups (Jan 12-18): herO, MaxPax, Solar win0
StarCraft 2
General
Behind the Blue - Team Liquid History Book Clem wins HomeStory Cup 28 How do you think the 5.0.15 balance patch (Oct 2025) for StarCraft II has affected the game? Rongyi Cup S3 - Preview & Info HomeStory Cup 28 - Info & Preview
Tourneys
PIG STY FESTIVAL 7.0! (19 Feb - 1 Mar) WardiTV Mondays $21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7) Sparkling Tuna Cup - Weekly Open Tournament $5,000 WardiTV Winter Championship 2026
Strategy
Custom Maps
Map Editor closed ? [A] Starcraft Sound Mod
External Content
The PondCast: SC2 News & Results Mutation # 511 Temple of Rebirth Mutation # 510 Safety Violation Mutation # 509 Doomsday Report
Brood War
General
StarCraft player reflex TE scores BW General Discussion Recent recommended BW games BGH Auto Balance -> http://bghmmr.eu/ Can someone share very abbreviated BW cliffnotes?
Tourneys
[Megathread] Daily Proleagues Escore Tournament StarCraft Season 1 Small VOD Thread 2.0 KCM Race Survival 2026 Season 1
Strategy
Zealot bombing is no longer popular? Simple Questions, Simple Answers Current Meta Soma's 9 hatch build from ASL Game 2
Other Games
General Games
Diablo 2 thread Battle Aces/David Kim RTS Megathread EVE Corporation Nintendo Switch Thread Path of Exile
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread YouTube Thread The Games Industry And ATVI Things Aren’t Peaceful in Palestine
Fan Clubs
The herO Fan Club! The IdrA Fan Club
Media & Entertainment
[Manga] One Piece Anime Discussion Thread
Sports
2024 - 2026 Football Thread
World Cup 2022
Tech Support
TL Community
The Automated Ban List
Blogs
Play, Watch, Drink: Esports …
TrAiDoS
My 2025 Magic: The Gathering…
DARKING
Life Update and thoughts.
FuDDx
How do archons sleep?
8882
James Bond movies ranking - pa…
Topin
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1442 users

The Big Programming Thread - Page 51

Forum Index > General Forum
Post a Reply
Prev 1 49 50 51 52 53 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
freelander
Profile Blog Joined December 2004
Hungary4707 Posts
April 25 2011 13:59 GMT
#1001
On April 25 2011 10:44 HowitZer wrote:
Show nested quote +
On April 25 2011 10:34 freelander wrote:
what should I learn to be a webprogrammer?

I have C++, Java, and some script languege knowledge (python, lua)
no php though


Try out Visual Web Developer by Microsoft. It's a free integrated development environment for developing asp.net applications. The backend code can be written in C# which is quite a bit like C++. ASP.NET is a very powerful tool for developing web applications. Remember that everything on the web ends up in html format.


You're best off learning a web framework, like Django (Python), Ruby on Rails, or ASP.NET (etc). I personally work with Rails and definitely recommend it, but there are of course many good options out there. Basically -> do your research -> pick a framework/language -> buy/read a recommended book/tutorial on it -> start building apps -> learn as you go (ask questions on irc/stack overflow/hacker news). Learning html/css and eventually javascript (probably in the context of jQuery) are of course musts.

Django has excellent docs and Rails Tutorial is an excellent intro to Rails.


thanks guys
And all is illuminated.
FezTheCaliph
Profile Joined February 2010
United States492 Posts
April 26 2011 02:31 GMT
#1002
I'm having trouble debugging my javascript code. I downloaded firebug but cant get it to work
It is better to be on hand with ten men then absent with ten thousand
haduken
Profile Blog Joined April 2003
Australia8267 Posts
April 26 2011 03:29 GMT
#1003
Why not just use chrome. It has a in build JS debugger.
Rillanon.au
Adeny
Profile Blog Joined January 2009
Norway1233 Posts
Last Edited: 2011-04-26 18:28:37
April 26 2011 18:25 GMT
#1004
Hi. So I'm learning C# and I need inspiration for a project. I'd like to get used to working with LINQ and extension methods, as well as general OOP stuff. So if anyone is taking OOP or C# classes I'd like to see some of the assignments!
Selemender
Profile Joined May 2010
Netherlands54 Posts
April 26 2011 21:32 GMT
#1005
On April 26 2011 11:31 FezTheCaliph wrote:
I'm having trouble debugging my javascript code. I downloaded firebug but cant get it to work


Whats not working exactly? Should be as simple as download add-on for Firefox, restart the browser, open page, right mouse button -> inspect element. And you could indeed use Chrome but Firebug is supposed to work.
Frigo
Profile Joined August 2009
Hungary1023 Posts
Last Edited: 2011-04-27 11:10:00
April 27 2011 09:43 GMT
#1006
Having succeeded in emulating final classes in C++, I'm trying to do the same with final methods. I have a class template that has virtual constructor(s) and are friends with the base class (but not the subclass), and all I'm trying to do is to use it as a dummy parameter which the subclass can not pass by value, essentially forcing the method to have a different signature.

However I came across some bullshit. Anyone care to explain it?

+ Show Spoiler +


#include <iostream>

using namespace std;

template <class T>
class Final
{

private:

Final (int) {}
virtual ~Final () {}

class Wrapper
{
public:
typedef T Type;
};

friend class Wrapper::Type;

};

class Base
{
public:
virtual ~Base () {}
virtual int f (Final<Base> = 0) {return 1;}
};

class Sub :
public Base
{
public:
virtual ~Sub () {}
virtual int f (Final<Base> = 0) {return 2;}
};


int main (int argc, char** argv)
{
if(argc||argv){}
Base* base = new Base();
Base* sub = new Sub();
cout << base->f() << endl;
cout << sub->f() << endl;
}



c:\code\test>compile.bat

c:\code\test>main
1
2


http://www.fimfiction.net/user/Treasure_Chest
Kaiwa
Profile Blog Joined August 2010
Netherlands2209 Posts
Last Edited: 2011-04-27 11:07:23
April 27 2011 11:02 GMT
#1007
+ Show Spoiler +
Base* base = new Sub();


That might be it ^^

Edit: Now that I think about it more. Sub inherits from Base, so it doesn't give an error. However the sub pointer is stored in base. This would imply that it should use the base functionality and should therefor return 1. Hmm, any specific reason why you use new Sub() instead of Base()?
시크릿 / 씨스타 / 에이핑크 / 윤하 / 가비앤제이
Frigo
Profile Joined August 2009
Hungary1023 Posts
Last Edited: 2011-04-27 11:24:11
April 27 2011 11:08 GMT
#1008
On April 27 2011 20:02 Kaiwa wrote:
+ Show Spoiler +
Base* base = new Sub();


That might be it ^^

Fix'd, though the issue still stands, Sub shouldn't be able to initalize a Final<Base> as default parameter, since the constructor is private, as Base is the only friend.

Edit: By the way, the more I think about it, the clearer it becomes that it isn't possible to seal a method that was once declared virtual in any of the parent classes:

+ Show Spoiler +


class Base
{
public:
virtual ~Base () {}
virtual int f () {return 1;}
};

class Sub :
public Base
{
public:
virtual ~Sub () {}
int f () {return 2;} // override, non-virtual
// int f (int = 0) {return 2;} // do not override Base::f() but shadow it
// int f (Final<Sub> = Final<Sub>()) {return 2;} // do not override Base::f() but shadow it in such a way to prevent subclasses from declaring a function with the same signature
};

class Grandchild :
public Sub
{
public:
virtual ~Grandchild () {}
virtual int f () {return 3;}
};


Whatever you do in Sub, either you override or shadow or shadow and prevent methods with the same signature, it is not possible to prevent Grandchild from overriding Base::f(); i.e. you can't override and seal.
http://www.fimfiction.net/user/Treasure_Chest
Kaiwa
Profile Blog Joined August 2010
Netherlands2209 Posts
Last Edited: 2011-04-27 11:21:39
April 27 2011 11:15 GMT
#1009
What about the comparisons.

+ Show Spoiler +
Final<Base> = 0


If I replace it for + Show Spoiler +
Final<Base>* = 0
I get the output

+ Show Spoiler +

1
2


So the code would be:

+ Show Spoiler +

#include <iostream>

using namespace std;

template <class T>
class Final
{
private:
Final (int) {}
virtual ~Final () {}

class Wrapper
{
public:
typedef T Type;
};

friend class Wrapper;
};

class Base
{
public:
virtual ~Base () {}
virtual int f (Final<Base>* = 0) {return 1;}
};

class Sub :
public Base
{
public:
virtual ~Sub () {}
virtual int f (Final<Base>* = 0) {return 2;}
};


int main (int argc, char** argv)
{
if(argc||argv){}
Base* base = new Base();
Sub* sub = new Sub();
cout << base->f() << endl;
cout << sub->f() << endl;
}


I fixed some other stuff too that the compiler was whining about.
시크릿 / 씨스타 / 에이핑크 / 윤하 / 가비앤제이
japro
Profile Joined August 2010
172 Posts
Last Edited: 2011-04-27 11:28:55
April 27 2011 11:28 GMT
#1010
Uhm, I don't get it. In java every method is implicitly virtual so you need final to keep it from being virtual. In C++ you have to explicitly declare virtual so you can override them (in the polymorpic sense). So if you want the method to be "final" just don't make it virtual in the first place.
Kaiwa
Profile Blog Joined August 2010
Netherlands2209 Posts
April 27 2011 11:31 GMT
#1011

Whatever you do in Sub, either you override or shadow or shadow and prevent methods with the same signature, it is not possible to prevent Grandchild from overriding Base::f(); i.e. you can't override and seal.


So the way I look at it is, you want Base, Subs and maybe even Subs of that. You want to receive different values of each while still storing them in the same Wrapper?

What I would suggest you looking into is delegates for C++. It's not very elegant or anything but I think it might work better than this approach.

Basicly you create a static class with the 2 static functions representing your Base and Sub classes. Then in both of the classes you create a function-pointer (delegate). This delegate is then filled in within the constructor of the classes.

When you then call your function through the delegate it will be the right one. Hope it still makes sense and that I interpreted it correctly.

Gotta go now, i'll check back later
시크릿 / 씨스타 / 에이핑크 / 윤하 / 가비앤제이
Frigo
Profile Joined August 2009
Hungary1023 Posts
Last Edited: 2011-04-27 11:40:46
April 27 2011 11:32 GMT
#1012
On April 27 2011 20:15 Kaiwa wrote:
If I replace it for[...]


Nah, it won't work pointers. Final<Base>'s main use would be to allow access from Base, but forbid access from its subclasses (it befriends Base via the inner class, aka friend class Wrapper::Type).
But it looks like the compiler either does not enforce visibility constraints when it checks default parameters (Final<Base> construction from int should be allowed only in Base), or something is in play here I don't know about.

On April 27 2011 20:28 japro wrote:
Uhm, I don't get it. In java every method is implicitly virtual so you need final to keep it from being virtual. In C++ you have to explicitly declare virtual so you can override them (in the polymorpic sense). So if you want the method to be "final" just don't make it virtual in the first place.


It's not so simple. Once you declare a method virtual, it stays virtual, no matter if you declare it non-virtual in a subclass.

Kaiwa
What I would suggest you looking into is delegates for C++. It's not very elegant or anything but I think it might work better than this approach.


Hmm this sounds promising, I'll check it out.
http://www.fimfiction.net/user/Treasure_Chest
heishe
Profile Blog Joined June 2009
Germany2284 Posts
Last Edited: 2011-04-27 11:44:42
April 27 2011 11:43 GMT
#1013
Frigo, why do you want final methods (or classes for that matter)? They smell like bad design a lot and that stuff doesn't belong to C++ (there's a reason it's not natively supported and isn't part of C++0x). I've never used them and never saw a reason to. In Java it seemed like another one of those obsolete safety features which enabled you to say to another programmer who is a potential evil villain and who is playing around with your classes: "Hey you idiot, don't override this method or you'll break something!".

Nobody should ever want to override methods of classes about which he doesn't know anything about anyways. And if you're using them yourself you should know what to override and what not to override anyways.

If you value your soul, never look into the eye of a horse. Your soul will forever be lost in the void of the horse.
Clearout
Profile Blog Joined April 2010
Norway1060 Posts
April 29 2011 15:22 GMT
#1014
I'm having some strange trouble regarding a program I'm making. Everything runs fine when I start it in Eclipse, but when I make a runnable .jar file one of games won't start. Nothing crashes, no errors or any of that, just nothing happens.

I've checked it over several computers as well so it's not just me. What I was wondering though was if someone who runs OS X or linux would bother downloading the file, and making it into a .jar to see if it works there. Don't know any other way to look for what it can be, as this was the only thing I haven't been able to check of the things the lab engineer told me to try.

I would really appreciate if someone would bother to do this.

Download link to the .zip :linky
really?
WitchDoctor
Profile Joined May 2011
Canada18 Posts
Last Edited: 2011-05-10 02:06:39
May 02 2011 18:49 GMT
#1015
Does anybody want to work on a community website just like teamliquid.net but for Diablo 3?

I have domain name registered for the site. [modedit]


Contact me if you follow under these categories:

You love D3...
You love designing website
You are bored this summer
You want to build a portfolio

Kudos !
WitchDoctor

User was warned for this post
Pm me if your interested in developing a website. (Registered domain name: www.diablogaming.com)
darmousseh
Profile Blog Joined May 2010
United States3437 Posts
May 03 2011 22:16 GMT
#1016
Anyone know of a binding or library for sc2 replay parsing in ruby?
Developer for http://mtgfiddle.com
Manit0u
Profile Blog Joined August 2004
Poland17654 Posts
May 04 2011 18:26 GMT
#1017
Could someone please help me out here? I'm a noob and I have a momentary lapse of reason right now as I can't for the life of me recall how to properly loop my program so it won't exit after one go (only when someone enters 0 in any case he's asked to enter input)...
I don't need a ready solution, if you could just push me along by suggesting what should I use I'll be fine (I'm trying to learn some programming for personal uses mostly, like this dice throw generator here).

It's ANSI C if you can't tell.

+ Show Spoiler [code] +


#include <stdio.h>
#include <stdlib.h>
#include <time.h>

struct DiceConfiguration
{
int DiceNumber;
int DiceType;
};

struct DiceThrowsResult
{
int DiceNumber;
int Sum;
int ThrowsResults[];
};

struct DiceConfiguration* GetConfiguration(void);
struct DiceThrowsResult* ThrowDices(struct DiceConfiguration *config);
int ThrowDice(struct DiceConfiguration *config);
void PrintDiceThrowsResult(struct DiceThrowsResult *result);

int main(void)
{
srand((unsigned int) time(0)); // random seed

struct DiceConfiguration *config;
config = GetConfiguration();

struct DiceThrowsResult *result;
result = ThrowDices(config);

PrintDiceThrowsResult(result);

free(config);
free(result);

return 0;
}

struct DiceConfiguration* GetConfiguration(void)
{
struct DiceConfiguration *config;
config = malloc(sizeof(struct DiceConfiguration));

printf("Enter the number of dice: ");
scanf("%d", &config->DiceNumber);
printf("Enter dice type (sides) : ");
scanf("%d", &config->DiceType);

return config;
}

struct DiceThrowsResult* ThrowDices(struct DiceConfiguration *config)
{
struct DiceThrowsResult *result;
result = malloc(sizeof(struct DiceThrowsResult) + config->DiceNumber * sizeof(int));
result->DiceNumber = config->DiceNumber;

for (int i = 0; i < config->DiceNumber; i++)
{
result->ThrowsResults[i] = ThrowDice(config);
result->Sum += result->ThrowsResults[i];
}

return result;
}

int ThrowDice(struct DiceConfiguration *config)
{
return rand() % config->DiceType + 1;
}

void PrintDiceThrowsResult(struct DiceThrowsResult *result)
{

for (int i = 0; i < result->DiceNumber; i++)
{
printf("%d ", result->ThrowsResults[i]);
}

printf("Sum: %d\n", result->Sum);
}

Time is precious. Waste it wisely.
Pawsom
Profile Blog Joined February 2009
United States928 Posts
Last Edited: 2011-05-04 20:13:39
May 04 2011 20:08 GMT
#1018
On May 05 2011 03:26 Manit0u wrote:
Could someone please help me out here? I'm a noob and I have a momentary lapse of reason right now as I can't for the life of me recall how to properly loop my program so it won't exit after one go (only when someone enters 0 in any case he's asked to enter input)...
I don't need a ready solution, if you could just push me along by suggesting what should I use I'll be fine (I'm trying to learn some programming for personal uses mostly, like this dice throw generator here).

It's ANSI C if you can't tell.

+ Show Spoiler [code] +


#include <stdio.h>
#include <stdlib.h>
#include <time.h>

struct DiceConfiguration
{
int DiceNumber;
int DiceType;
};

struct DiceThrowsResult
{
int DiceNumber;
int Sum;
int ThrowsResults[];
};

struct DiceConfiguration* GetConfiguration(void);
struct DiceThrowsResult* ThrowDices(struct DiceConfiguration *config);
int ThrowDice(struct DiceConfiguration *config);
void PrintDiceThrowsResult(struct DiceThrowsResult *result);

int main(void)
{
srand((unsigned int) time(0)); // random seed

struct DiceConfiguration *config;
config = GetConfiguration();

struct DiceThrowsResult *result;
result = ThrowDices(config);

PrintDiceThrowsResult(result);

free(config);
free(result);

return 0;
}

struct DiceConfiguration* GetConfiguration(void)
{
struct DiceConfiguration *config;
config = malloc(sizeof(struct DiceConfiguration));

printf("Enter the number of dice: ");
scanf("%d", &config->DiceNumber);
printf("Enter dice type (sides) : ");
scanf("%d", &config->DiceType);

return config;
}

struct DiceThrowsResult* ThrowDices(struct DiceConfiguration *config)
{
struct DiceThrowsResult *result;
result = malloc(sizeof(struct DiceThrowsResult) + config->DiceNumber * sizeof(int));
result->DiceNumber = config->DiceNumber;

for (int i = 0; i < config->DiceNumber; i++)
{
result->ThrowsResults[i] = ThrowDice(config);
result->Sum += result->ThrowsResults[i];
}

return result;
}

int ThrowDice(struct DiceConfiguration *config)
{
return rand() % config->DiceType + 1;
}

void PrintDiceThrowsResult(struct DiceThrowsResult *result)
{

for (int i = 0; i < result->DiceNumber; i++)
{
printf("%d ", result->ThrowsResults[i];
}

printf("Sum: %d\n", result->Sum);
}



So try making a loop inside main, around the function calls to ThrowDices() and PrintDiceThrowsResults(). Do you know the syntax for a while loop in C?

You will need to ask the user to if he wants to continue, and use this input as the condition in your loop. Take a try at this, and post back if you need help.

A basic loop could look like:

+ Show Spoiler +

while (continue != FALSE)
{
doStuff();

doMoreShit();

continue = getContinue();
}

Manit0u
Profile Blog Joined August 2004
Poland17654 Posts
Last Edited: 2011-05-04 20:48:29
May 04 2011 20:44 GMT
#1019
On May 05 2011 05:08 Pawsom wrote:
Show nested quote +
On May 05 2011 03:26 Manit0u wrote:
Could someone please help me out here? I'm a noob and I have a momentary lapse of reason right now as I can't for the life of me recall how to properly loop my program so it won't exit after one go (only when someone enters 0 in any case he's asked to enter input)...
I don't need a ready solution, if you could just push me along by suggesting what should I use I'll be fine (I'm trying to learn some programming for personal uses mostly, like this dice throw generator here).

It's ANSI C if you can't tell.

+ Show Spoiler [code] +


#include <stdio.h>
#include <stdlib.h>
#include <time.h>

struct DiceConfiguration
{
int DiceNumber;
int DiceType;
};

struct DiceThrowsResult
{
int DiceNumber;
int Sum;
int ThrowsResults[];
};

struct DiceConfiguration* GetConfiguration(void);
struct DiceThrowsResult* ThrowDices(struct DiceConfiguration *config);
int ThrowDice(struct DiceConfiguration *config);
void PrintDiceThrowsResult(struct DiceThrowsResult *result);

int main(void)
{
srand((unsigned int) time(0)); // random seed

struct DiceConfiguration *config;
config = GetConfiguration();

struct DiceThrowsResult *result;
result = ThrowDices(config);

PrintDiceThrowsResult(result);

free(config);
free(result);

return 0;
}

struct DiceConfiguration* GetConfiguration(void)
{
struct DiceConfiguration *config;
config = malloc(sizeof(struct DiceConfiguration));

printf("Enter the number of dice: ");
scanf("%d", &config->DiceNumber);
printf("Enter dice type (sides) : ");
scanf("%d", &config->DiceType);

return config;
}

struct DiceThrowsResult* ThrowDices(struct DiceConfiguration *config)
{
struct DiceThrowsResult *result;
result = malloc(sizeof(struct DiceThrowsResult) + config->DiceNumber * sizeof(int));
result->DiceNumber = config->DiceNumber;

for (int i = 0; i < config->DiceNumber; i++)
{
result->ThrowsResults[i] = ThrowDice(config);
result->Sum += result->ThrowsResults[i];
}

return result;
}

int ThrowDice(struct DiceConfiguration *config)
{
return rand() % config->DiceType + 1;
}

void PrintDiceThrowsResult(struct DiceThrowsResult *result)
{

for (int i = 0; i < result->DiceNumber; i++)
{
printf("%d ", result->ThrowsResults[i];
}

printf("Sum: %d\n", result->Sum);
}



So try making a loop inside main, around the function calls to ThrowDices() and PrintDiceThrowsResults(). Do you know the syntax for a while loop in C?

You will need to ask the user to if he wants to continue, and use this input as the condition in your loop. Take a try at this, and post back if you need help.

A basic loop could look like:

+ Show Spoiler +

while (continue != FALSE)
{
doStuff();

doMoreShit();

continue = getContinue();
}



You mean something like that?

+ Show Spoiler +


while (DiceNumber > 0 && DiceType > 0)
{

do stuff

}



Then the entire thing should become a while loop...
The problem I'm facing right now is the right place to put the loop, as this while checks for 2 variables which should be assigned before the loop and it would be pointless to do this stuff over and over again with the same variables (infinite loop welcome to).
My mind is completely empty right now, I need to think about it.

Edit: Nevermind, I think I got it.
Time is precious. Waste it wisely.
Pawsom
Profile Blog Joined February 2009
United States928 Posts
Last Edited: 2011-05-04 20:54:18
May 04 2011 20:47 GMT
#1020
On May 05 2011 05:44 Manit0u wrote:
Show nested quote +
On May 05 2011 05:08 Pawsom wrote:
On May 05 2011 03:26 Manit0u wrote:
Could someone please help me out here? I'm a noob and I have a momentary lapse of reason right now as I can't for the life of me recall how to properly loop my program so it won't exit after one go (only when someone enters 0 in any case he's asked to enter input)...
I don't need a ready solution, if you could just push me along by suggesting what should I use I'll be fine (I'm trying to learn some programming for personal uses mostly, like this dice throw generator here).

It's ANSI C if you can't tell.

+ Show Spoiler [code] +


#include <stdio.h>
#include <stdlib.h>
#include <time.h>

struct DiceConfiguration
{
int DiceNumber;
int DiceType;
};

struct DiceThrowsResult
{
int DiceNumber;
int Sum;
int ThrowsResults[];
};

struct DiceConfiguration* GetConfiguration(void);
struct DiceThrowsResult* ThrowDices(struct DiceConfiguration *config);
int ThrowDice(struct DiceConfiguration *config);
void PrintDiceThrowsResult(struct DiceThrowsResult *result);

int main(void)
{
srand((unsigned int) time(0)); // random seed

struct DiceConfiguration *config;
config = GetConfiguration();

struct DiceThrowsResult *result;
result = ThrowDices(config);

PrintDiceThrowsResult(result);

free(config);
free(result);

return 0;
}

struct DiceConfiguration* GetConfiguration(void)
{
struct DiceConfiguration *config;
config = malloc(sizeof(struct DiceConfiguration));

printf("Enter the number of dice: ");
scanf("%d", &config->DiceNumber);
printf("Enter dice type (sides) : ");
scanf("%d", &config->DiceType);

return config;
}

struct DiceThrowsResult* ThrowDices(struct DiceConfiguration *config)
{
struct DiceThrowsResult *result;
result = malloc(sizeof(struct DiceThrowsResult) + config->DiceNumber * sizeof(int));
result->DiceNumber = config->DiceNumber;

for (int i = 0; i < config->DiceNumber; i++)
{
result->ThrowsResults[i] = ThrowDice(config);
result->Sum += result->ThrowsResults[i];
}

return result;
}

int ThrowDice(struct DiceConfiguration *config)
{
return rand() % config->DiceType + 1;
}

void PrintDiceThrowsResult(struct DiceThrowsResult *result)
{

for (int i = 0; i < result->DiceNumber; i++)
{
printf("%d ", result->ThrowsResults[i];
}

printf("Sum: %d\n", result->Sum);
}



So try making a loop inside main, around the function calls to ThrowDices() and PrintDiceThrowsResults(). Do you know the syntax for a while loop in C?

You will need to ask the user to if he wants to continue, and use this input as the condition in your loop. Take a try at this, and post back if you need help.

A basic loop could look like:

+ Show Spoiler +

while (continue != FALSE)
{
doStuff();

doMoreShit();

continue = getContinue();
}



You mean something like that?

+ Show Spoiler +


while (DiceNumber > 0 && DiceType > 0)
{

do stuff

}



Then the entire thing should become a while loop...
The problem I'm facing right now is the right place to put the loop, as this while checks for 2 variables which should be assigned before the loop and it would be pointless to do this stuff over and over again with the same variables (infinite loop welcome to).
My mind is completely empty right now, I need to think about it.



No you should declare another variable. Ask the user if they want to roll again, and store their input in that variable. Loop based on the value of that variable.

+ Show Spoiler +


while( repeat != 'n' )
{
result = ThrowDices(config);

PrintDiceThrowsResult(result);

printf("Want to play again? Enter y/n.");

scanf("%c", &repeat);
}



Did you find the dice program somewhere online? It's well written.
Prev 1 49 50 51 52 53 1032 Next
Please log in or register to reply.
Live Events Refresh
uThermal 2v2 Circuit
12:00
Monthly #2 - February
WardiTV764
uThermal388
IndyStarCraft 273
TKL 216
SteadfastSC162
BRAT_OK 122
ForJumy 63
MindelVK40
Shameless37
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
uThermal 379
IndyStarCraft 273
TKL 216
SteadfastSC 162
BRAT_OK 120
ForJumy 63
MindelVK 40
StarCraft: Brood War
Britney 63426
Calm 8091
firebathero 2154
Flash 1735
Horang2 1095
Mini 789
GuemChi 721
Soma 341
actioN 331
ZerO 324
[ Show more ]
Last 235
Mong 201
Hyun 200
ggaemo 188
Mind 110
Sharp 109
Leta 94
Pusan 86
910 63
Sea.KH 53
Barracks 52
sorry 47
Free 46
Shuttle 40
Aegong 39
Shine 37
Backho 31
Movie 27
ToSsGirL 24
GoRush 21
IntoTheRainbow 18
zelot 14
scan(afreeca) 14
Icarus 5
Dota 2
XcaliburYe433
Fuzer 279
BananaSlamJamma229
Counter-Strike
fl0m1878
Super Smash Bros
Mew2King84
Heroes of the Storm
Khaldor414
Other Games
B2W.Neo2432
singsing2257
ZerO(Twitch)18
Organizations
Other Games
gamesdonequick1144
BasetradeTV104
StarCraft: Brood War
lovetv 23
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 11 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Jankos6316
Upcoming Events
WardiTV Winter Champion…
1h 34m
OSC
10h 34m
Replay Cast
19h 34m
Wardi Open
22h 34m
Monday Night Weeklies
1d 3h
Sparkling Tuna Cup
1d 20h
LiuLi Cup
1d 21h
Reynor vs Creator
Maru vs Lambo
PiGosaur Monday
2 days
LiuLi Cup
2 days
Clem vs Rogue
SHIN vs Cyan
The PondCast
3 days
[ Show More ]
KCM Race Survival
3 days
LiuLi Cup
3 days
Scarlett vs TriGGeR
ByuN vs herO
Online Event
4 days
LiuLi Cup
4 days
Serral vs Zoun
Cure vs Classic
LiuLi Cup
5 days
Sparkling Tuna Cup
6 days
LiuLi Cup
6 days
Liquipedia Results

Completed

CSL 2025 WINTER (S19)
Rongyi Cup S3
Underdog Cup #3

Ongoing

KCM Race Survival 2026 Season 1
Nations Cup 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
SL Budapest Major 2025
ESL Impact League Season 8

Upcoming

Escore Tournament S1: W8
Acropolis #4
IPSL Spring 2026
HSC XXIX
uThermal 2v2 2026 Main Event
Bellum Gens Elite Stara Zagora 2026
RSL Revival: Season 4
WardiTV Winter 2026
LiuLi Cup: 2025 Grand Finals
CCT Season 3 Global Finals
FISSURE Playground #3
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League Season 23
ESL Pro League Season 23
PGL Cluj-Napoca 2026
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.