• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 13:15
CET 19:15
KST 03:15
  • 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
RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10[ASL20] Finals Preview: Arrival13
Community News
[TLMC] Fall/Winter 2025 Ladder Map Rotation12Weekly Cups (Nov 3-9): Clem Conquers in Canada4SC: Evo Complete - Ranked Ladder OPEN ALPHA8StarCraft, SC2, HotS, WC3, Returning to Blizzcon!45$5,000+ WardiTV 2025 Championship7
StarCraft 2
General
Mech is the composition that needs teleportation t RotterdaM "Serral is the GOAT, and it's not close" RSL Season 3 - RO16 Groups C & D Preview [TLMC] Fall/Winter 2025 Ladder Map Rotation TL.net Map Contest #21: Winners
Tourneys
RSL Revival: Season 3 Sparkling Tuna Cup - Weekly Open Tournament Constellation Cup - Main Event - Stellar Fest Tenacious Turtle Tussle Master Swan Open (Global Bronze-Master 2)
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 499 Chilling Adaptation Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened Mutation # 496 Endless Infection
Brood War
General
FlaSh on: Biggest Problem With SnOw's Playstyle What happened to TvZ on Retro? SnOw's ASL S20 Finals Review BW General Discussion Brood War web app to calculate unit interactions
Tourneys
[Megathread] Daily Proleagues Small VOD Thread 2.0 [BSL21] RO32 Group D - Sunday 21:00 CET [BSL21] RO32 Group C - Saturday 21:00 CET
Strategy
PvZ map balance Current Meta Simple Questions, Simple Answers How to stay on top of macro?
Other Games
General Games
Path of Exile Stormgate/Frost Giant Megathread Nintendo Switch Thread Clair Obscur - Expedition 33 Beyond All Reason
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
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread US Politics Mega-thread Artificial Intelligence Thread Canadian Politics Mega-thread
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
Movie Discussion! [Manga] One Piece Anime Discussion Thread Korean Music Discussion Series you have seen recently...
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
Dyadica Gospel – a Pulp No…
Hildegard
Coffee x Performance in Espo…
TrAiDoS
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Reality "theory" prov…
perfectspheres
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2038 users

The Big Programming Thread - Page 80

Forum Index > General Forum
Post a Reply
Prev 1 78 79 80 81 82 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.
KaiserJohan
Profile Joined May 2010
Sweden1808 Posts
September 21 2011 21:26 GMT
#1581
On September 18 2011 01:21 Shootist wrote:
Out of curiosity, what domain are most of the programmers/developers here in? Web, mobile, enterprise systems, etc?

I run a little web agency where I also do the web development work (HTML5/PHP/MySQL).


My field is telecommunications, fancy word for network programming. I work as an IT consultant though so it pretty much depends on the project I'm working on, but right now it's with Ericsson which is great because that's my speciality.

(oh and I hate web development )
England will fight to the last American
Frigo
Profile Joined August 2009
Hungary1023 Posts
Last Edited: 2011-09-21 22:52:23
September 21 2011 22:43 GMT
#1582
On September 22 2011 05:19 Bigpet wrote:
Also hurray for the formal signing of C++11 as an ISO standard. I'm hereby vowing that I will never again use memcpy() on any project where I'm allowed to use C++11. RValue references (move constructors specifically) and the new Array class (well not so new, it's been in TR1) will make memcpy finally obsolete for me. With the possible exception of having to use shitty APIs that make me do it.


C++11 has some cool features I've been missing for ages:

* non-const copying/moving from temporary objects - this removes the need for const correctness entirely for classes for which you do not want const behavior; this wasn't the case till now since temporary objects were implicitly convertible only to const references, which caused an avalanche effect in the entire class, requiring const correctness everywhere
* variadic templates, macros, typesafe functions - I don't need to explain how useful they are
* perfect forwarding of parameters - my pointer wrapper wouldn't be possible without it
* final classes and methods - I haven't been able to get them working quite yet
* initializer lists - for any custom array class, though variadic constructors work just as well
* constructor calling another constructor - would be better with "this" and "super" keywords, but the latter is not exactly possible due to multiple inheritance
* auto and decltype - decltype/typeof should have been in the first standard, they are infinitely useful; in fact, for a long time I tought typeof is in standard c++
* strongly typed nullptr, enums - typesafe null was already possible, typesafe enums not quite so due to too much overhead, still no typesafe boolean
* template typedefs - long overdue
* threads - ditto; I have yet to play with them though
* reference wrappers - they are useful but I have better
* function wrappers - ditto


Features that are quite frankly useless or outright dangerous:

* explicit conversion operators - just use toWhatever() methods and let's forget about silly casts
* user defined literals - just encourages unreadable cluttered code, it will be abused much more than operator overloading
* compatibility with C/C++ - it would be time to drop any backwards compatibility, they cause insane complications
* lambda functions - opinions vary, I think they just make the code unreadable
* generalized constant expressions - and yet still no functions that can be calculated in compile-time and used in constant expressions
* foreach loop - it is already possible with macros with even nicer syntax, no type information needed
* alternate function syntax - I didn't like it in the SPECS grammar either, and I don't like them here either; people just got used to the C-like function signature syntax, and this new style do not have any visible advantage, other than easier compiler and grammar design
* unrestricted unions - unions were pretty useless (and quite dangerous) to begin with, they should be dropped altogether
* various unicode encodings and string literals - I do not understand why can't everything be in either UTF-8 *or* UTF-32; UTF-8 has already proven itself, or if it causes problems, UTF-32
* the "delete" keyword applied to constructors or functions is a mistake; it violates the contract of the class, it should throw some kind of UnsupportedOperationException instead of compile error
* hash tables - almost everyone already has some kind of hash table implementation; standardizing it is cool, but making a standard hash function that may or may not fulfill a defined quality (universal hashing, perfect hashing) is pointless; also, linear chaining sucks, hash table with universal hash function + set instead of chaining is best
* regular expressions - worse than in Java
* smart pointers - KILL IT WITH FIRE, they fail even in the case of a doubly linked list, they simply can NOT replace garbage collection
* random number generators - IMHO random number generators shouldn't be in the core part of the language


Features still missing from it and other unsolved problems

* PROPER EXCEPTION HANDLING AND TYPE SYSTEM ARRRRRGGGHHH; they even removed exception specifications the fools
* the type system is still flawed, instead of hacking it with rvalue references and such, they should redesign it; it makes no sense to have pass by value, pointer, reference, rvalue reference, and const versions of these, when you can get by 2 of these, or 3 if you really want to have both heap and stack allocation
* also, clear distinction between polymorphic and value types; I had weeks of headaches trying to prevent object slicing arising from passing a subclass by value; walks hand in hand with assignment operators unfortunately
* garbage collection, man! it is really, really useful; everything could be heap allocated if moving is allowed and a generational/incremental collector is used, but can be used even if both heap and stack allocation is kept
* packages/modules are LONG, LONG OVERDUE, #include is absurd
* no definite sizes for primitives, altough I have some template metaprogramming tricks that only accepts integers of a given size and signedness, or causes a compilation failure, so while it is not an immediate concern, it should be addressed properly nonetheless; primitives really should be called int32, int64, uint32, etc
* a resultof keyword to determine the return type of a function with a given signature, with SFINAE propagation if the function does not exist
* still no goddamn typesafe booleans
* order of evaluation is still not defined
* too much "undefined behavior", a worthy standard should have exactly ZERO of these
* default constructor, copy constructor or assignment operator SHOULD NOT be generated unless asked for; there should be a Copyable or some other keyword to enable it
* get rid of multiple inheritance
* static_assert is nice, but concepts would be nicer
* precedence amongst implicit conversion operators, this came up surprising often
* multimethods that select the appropriate function to called based on the dynamic type of the parameter; arises naturally in game logic design where you have a nice Actor base class and you need different interactions between actors based on what exactly are they
http://www.fimfiction.net/user/Treasure_Chest
Sporadic44
Profile Blog Joined January 2011
United States533 Posts
September 21 2011 23:14 GMT
#1583
On September 22 2011 06:21 SpoR wrote:
Your last name is spor, sick


yerr, you could say i'm a funguy
lol
I sorted out my issue regarding the code I posted yesterday. I added an extra step that I didnt need. Apparently you dont use edited fields for displaying alphabetic data. I shouldve seen that earlier!
"Opportunities multiply as they are seized."
doktorLucifer
Profile Blog Joined November 2008
United States855 Posts
September 22 2011 02:27 GMT
#1584
On September 22 2011 05:19 Bigpet wrote:
Show nested quote +
On September 22 2011 05:03 doktorLucifer wrote:
/*is the &* correct? I know that the formal parameters are usually dereferenced, and scanf usually needs an address operator. But since I'm passing an address in the first place, can I just use 'scanf("%d %d", x, y)' ? */

Yes &* is redundant unless the * operator is overloaded which it isn't here . (edit: looks like C code, so ignore the last part)

edit: OMG. Don't do the while(1);. Just use getchar() to halt the console until you press a button.

Also hurray for the formal signing of C++11 as an ISO standard. I'm hereby vowing that I will never again use memcpy() on any project where I'm allowed to use C++11. RValue references (move constructors specifically) and the new Array class (well not so new, it's been in TR1) will make memcpy finally obsolete for me. With the possible exception of having to use shitty APIs that make me do it.


I'm using while(1); since when I use getchar();, it sometimes fails to work, esp if there was a scanf(); earlier, i don't know why ;_;
SiKStArCuE
Profile Joined April 2011
United States19 Posts
September 22 2011 02:47 GMT
#1585
Hey guys I'm taking a CS 2 course right now that focuses on graphical stuff written in java. In this assignment I am supposed to create an ArrayList<Disk> instance variable to hold the collection of disks, also with an instance variable 'current' of type int that holds the index of the current disk. And pretty much I have a bunch of methods to draw the disk, add, remove, change color, etc.. But I am supposed to be able to move the up, down, left, and right arrow keys to change to whatever disk. Here's a snip of the code I'm having trouble with. The left and right arrow keys work when I want to change to a disk on the left or right. But I'm not sure how to do the Up and Down keys using this type of syntax? I know there's an easier way to do this doing something like (0,1) to move up, (1,0) to move left. Any help would be appreciated. Thx guys.

public void keyPressed( KeyEvent e ) {
int code = e.getKeyCode();

if( code == KeyEvent.VK_LEFT ) {
disks.get(current--);
}
else if( code == KeyEvent.VK_RIGHT ) {
disks.get(current++);
}
else if( code == KeyEvent.VK_UP ) {
}
else if( code == KeyEvent.VK_DOWN) {
}
Sc1pio
Profile Blog Joined August 2009
United States823 Posts
September 22 2011 20:33 GMT
#1586
Hey everybody I'm in a course teaching C++ to people who initially learned java and I'm having a ton of trouble with a couple particular errors.

The code and compiler output is located here.

In particular, the errors about array declaration (lines 32, 179, 234) are killing me right now, though any help at all would be appreciated.

Thanks a bunch.
"In the beginner's mind there are many possibilities, in the expert's there are few. " -Shunro Suzuki | fortuna fortes adiuvat
Frigo
Profile Joined August 2009
Hungary1023 Posts
Last Edited: 2011-09-22 22:40:51
September 22 2011 21:49 GMT
#1587
C++ arrays are quite unlike Java arrays, the best way to use them is to avoid them like plague, they are the single worst part of C++.

Dynamic length array parameters automatically decay into pointers, so if you have an f(double v[]) method, that is equivalent to an f(double*) method. Similarly, double[] as return type is equivalent to double*. Pointers to objects and arrays are not exactly distinguishable, and you especially can't get the length of an array from its pointer.

In essence, you are using {this, style, of initialization}, aka initializer list for pointers, at lines 32, 179, 188, 203, 234. I doubt it is legal. You are also mixing dynamic length arrays and static length arrays, nothing good can come of that.

My advice:
* Try using only static length arrays; double a[5] instead of double a[], double values[5] instead of double values[]. Perhaps it will work, perhaps not, my knowledge is a bit sketchy about static length arrays. Edit: NEVER MIND. I've tested a few cases, you can initialize and even assign static length arrays the way you want, BUT as member variables they automatically decay to pointers.
* If you use C++11, formerly known as C++0x, use std::initializer_list instead of arrays as parameter to the constructor.
* Like me, implement your own Array class that does not have any of the drawbacks of arrays, with an std::initializer_list constructor and assignment operator. Then the construction from initializer list you are trying will definitely work.

I recommend registering at Stack Overflow and asking your question there.

Edit: Looks like it is not possible to use an array as a default parameter: http://stackoverflow.com/questions/4894094/passing-an-array-as-a-parameter-with-default-values-into-int-main/4894140#4894140

Edit: Best I could come up with:
#include <Frigo/Lang/all>
#include <Frigo/Lang/all.cpp>

using namespace Frigo::Lang;
using namespace std;

class Test
{

public:

/*
* No parameter is given, we use {1, 2, 3, 4, 5}
*/

Test () :
n (5),
v (new int32[5])
{
for( int32 i = 0; i < n; i++ ){
v[i] = i + 1;
}
}

/*
* Initialize from static length array; static length array is passed by reference, ugly syntax
*/

template <int32 m>
Test (int32 (&p) [m]) :
n (m),
v (new int32[m])
{
for( int32 i = 0; i < n; i++ ){
v[i] = p[i];
}
}

/*
* Initialize from brace-enclosed initializer list, C++11 only
*/

Test (std::initializer_list<int32> list) :
n (static_cast<int32>(list.size())),
v (new int32[list.size()])
{
int32 i = 0;
for( auto iter = list.begin(); iter != list.end(); ++iter ){
v[i] = *iter;
i++;
}
}

~Test ()
{
delete [] v;
}

protected:

int32 n;
int32* v;

private:

Test (Test&);
Test& operator = (Test&);

};

template <class T, int32 n>
int32 lengthof (const T (&) [n])
{
return n;
}

int32 main (int32, char*[])
{
int32 v[] = {1, 2, 3}; // this is actually int32 v[3], not int32*
Test x;
Test y(v);
Test z{1, 2, 3, 4};
// Test z = {1, 2, 3, 4}; // DOES seem to involve copy constructor, contrary to established practice in other constructors where = is just syntactic sugar
}
http://www.fimfiction.net/user/Treasure_Chest
icystorage
Profile Blog Joined November 2008
Jollibee19350 Posts
Last Edited: 2011-09-23 02:57:30
September 23 2011 02:57 GMT
#1588
-module(chatbot).
-export([matches/2,matches/3,words/2]).

matches(H,{match,M}) -> matches(H,M,[]).
matches(_,[],Acc) -> Acc;
matches(H,[{I,L}|T],Acc) ->
matches(H,T,[lists:sublist(H,I,L)|Acc]).

words(String, Regexp) -> matches(String,re:matches(String, Regexp)).

Words_1 = "[^ ]+".
Words_2 = "[A-Za-z'-]+".


this doesnt compile and i dont know why D: im trying to turn each word in a string into a list.
but
Words_1 = "[^ ]+".      
Words_2 = "[A-Za-z'-]+".
doesnt compile, some sort of syntax error =/
can i ask anybody for help?
LiquidDota StaffAre you ready for a Miracle-? We are! The International 2017 Champions!
tISL
Profile Joined February 2011
Netherlands34 Posts
September 23 2011 09:48 GMT
#1589
Hey,

I've recently started programming XNA games. Followed a amount of tutorials and have some contacts that help me with small problems.

However, anyone can recommend me a book regarding XNA? I read some stuff on the web there are no decent books and you just have 'to do it'. I'm not really a fan of non-stop following tutorials. I like to read the proces and everything related to XNA by learning from a book.

Any help?
Rixxe
Profile Joined July 2011
United Kingdom136 Posts
September 23 2011 11:29 GMT
#1590
http://stackoverflow.com/questions/576893/xna-which-single-book-should-a-beginner-start-with

That gives you some indication of what people think, if not just go on Amazon and read the reviews. There are loads of books on that kind of stuff... however i do as you were told, just learn it by doing.

Can't say it was the most fun, but hey, it works!

Anyone have a good method of reading in files using Memory Reader in C#? (Talking files of 1gig+)
*bleep* you up in a gangsta style!
simmion
Profile Joined June 2011
United States34 Posts
September 23 2011 15:01 GMT
#1591
On September 17 2011 13:44 eFonSG wrote:
Show nested quote +
On September 17 2011 12:52 tofucake wrote:
On September 17 2011 12:30 eFonSG wrote:
Hey i was wondering if anyone with a decent amount of knowledge in Java could help me with some code? Im pretty confused right now, and ive been staring at my screen for a few hours hoping i would miraculously figure it out. I really only need some help getting started in the right direction, because im just lost from the start.

Elaborate? I know the OP says not to post and ask what's wrong, but you can post and say "I tried X, Y, and Z and I still don't know what's going on. Can anyone help?" That's actually the attitude I'd love to see going on.

On September 14 2011 08:14 Clank wrote:
On September 13 2011 13:26 catamorphist wrote:
On September 13 2011 10:59 Clank wrote:
ok, im in high school and looking for some good extracurriculars for colleges. I have limited knowledge in programming, as I've only taken 2 classes, one intro to basic at school, and then an intro to python. I did very well in those classes and enjoyed them , but still, im quite nooby. Basically what im wondering is, do you think it would be possible for me to try and learn how to make a very basic app for the app store? And if that would be too challenging, do you have any suggestions to try and incorporate programming into a fun, good extracurricular?


No, you could do it in a couple weeks worth of evenings. Go do it!


ok, thank you! any tips for getting starting?

Just Do It™. That's my approach.


Can do, Im trying to make a program that will ask for a user input for a full name, then re-arrange the order and capitalization to match the exercise ( and it forces me to use nextLine() rather than next()). For example
import java.util.Scanner;
public class ThreeNames{
public static void main(String[]args){
Scanner A = new Scanner (System.in);
System.out.print("Please enter your name: ");
String Name = A.nextLine();

The user would type in a full name, such as firstname middlename lastname, i need to then rearrange it so that it shows the initials(F.M.L), and then re-arrange it so that its Lastname, firstname M.
Ive been trying to use substring() to break apart the the string Name into just the first letters so that i can capitalize them

String B = (Name.substring(0,1)).toUpperCase());

This would give me the very fist letter of the first name so that i could capitalize it. My problem is that i dont know how to get the first letters of the middlename and lastname, so i can capitalize them and put them in proper format. I was under the assumption that substring() can only have ints as its argument and not whitespace characters, which was my first guess. But that failed pretty miserably. So im not really sure how to break up the string Name because i cant predict how long the name will be, and therefore cannot have an actual int value for the substring. Maybe im looking at it wrong, but any help would be greatly appreciated.




You can read the Whole string in and then split it on the space character to get 3 separate strings back, if you can assume that the user will input in the correct order then its pretty simple.

ex.

String fullName = key.readLine(); // key is a BufferedReader
String [] nameList = fullName.split(" ");// space might need escaped, cant remember
String firstName = nameList[0];
String middle = nameList[1];
String last = nameList[2];

char firstInitial = firstName.charAt(0);
// so on so forth.
"Ricky Bobby" -stephano
CrumpetGuvnor
Profile Joined November 2010
Australia302 Posts
September 24 2011 02:06 GMT
#1592
Hey guys I am rank 44 bronze league at Java, I've never posted here in the Java strategy forums and I was hoping someone could help me out. Basically this is the last method of my assignment that I need to write, and I'm having trouble and preferably it needs to be done in 2 hours. Any help would be appreciated.

/**
* Find the position in the observation array of the first value
* greater than or equal to the argument, if such an element exists
* For example, the first day of good rain would be one with rainfall >= 5mm
* @param large a double for the search condition value
* @return position of element satisfying search criteria
* or -1 if no value meets this condition
*/
public int findPosGreaterthan(double large) {

I think the /** text pretty much explains everything that needs doing but if not I will give a brief explanation. Basically the class is a rainfall (/any weather stat) recording class and the method is to find the first position within the array of values that a certain notable value occurs, determined by the user.

I'm thinking that a while loop is required however I have never written a while loop and whilst I understand the concept, I have no idea of how to structure it, what variables required etc.

Anyways, any help within the next two hours would be greatly appreciated and any input within the next 14 hours (which is when it is officially due) would also be appreciated, however I will be quite drunk by that stage...

Cheers
EvanED
Profile Joined October 2009
United States111 Posts
September 24 2011 04:01 GMT
#1593
On September 22 2011 07:43 Frigo wrote:
Features that are quite frankly useless or outright dangerous:

...
* lambda functions - opinions vary, I think they just make the code unreadable

Personally, I think there are enough cases where they are really helpful that they are a very welcome addition.

* foreach loop - it is already possible with macros with even nicer syntax, no type information needed

Nothing with macros is nicer syntax. :-)

Macros are a necessary evil and I wouldn't want them to go, but I do think that looking at how macros are used and adding first-class language support is a very worthwhile task. Macros have too many problems.

* the "delete" keyword applied to constructors or functions is a mistake; it violates the contract of the class, it should throw some kind of UnsupportedOperationException instead of compile error

Whoa, what?

If you have a function that always throws something like UnsupportedOperationException, that is a strong indication that your design is broken. Why would you have a runtime error when you could have a compile time one? What possible use could that have? Essentially the delete keyword in these ways is saying those function's aren't part of the class.

(There are some cases where an UnsupportedOperation is in some sense the least-broken approach, but it's still broken. If an operation is unsupported... it shouldn't be there!)

* smart pointers - KILL IT WITH FIRE, they fail even in the case of a doubly linked list, they simply can NOT replace garbage collection

While I am much less of a C++ fan than I was a while ago and think that basically everything should be written in a managed language nowadays and so agree with the second part, if you're forced into using C++, smart pointers make it way more bearable. Yes, you have to know what they can and can't do, but that's true of everything. C++ isn't exactly a hold-your-hand language.

Features still missing from it and other unsolved problems

* PROPER EXCEPTION HANDLING AND TYPE SYSTEM ARRRRRGGGHHH; they even removed exception specifications the fools

Exception specifications were removed because the original design was broken and idiotic (exactly because it wasn't part of the type system).

I'm not sure what I'd like to see here. On one hand, one of the most obnoxious things about Java to me in a lot of cases is its checked exceptions; but at the same time, it would be nice to have it check them on demand.

* order of evaluation is still not defined
* too much "undefined behavior", a worthy standard should have exactly ZERO of these

I go back and forth on this. On one hand, I see where you're coming from, but on the other... compiler writers really can (and do) take advantage of that undefined behavior.
Frosticles
Profile Joined May 2010
United States50 Posts
September 24 2011 23:13 GMT
#1594
Hey guys Im working on a program in c++ to output the weekly salary of employees but for some reason when I input the hours, it is giving me these ridiculous answers. Possibly the problem lies in the declaration of variables? im not sure.

+ Show Spoiler +

#include <iostream>
using namespace std;

int main ()
{
double hours;
double overtime;
double salary;
salary = (8 * hours);


cout << "Input the amount of hours worked: " <<endl;
cin >> hours;

if(hours<=40)
cout << "Your weekly salary is " << salary << " dollars" <<endl;

else if(hours>40)
cout << "Your weekly salaray is " << overtime << " dollars" << endl;


return 0;

}



MrShankly
Profile Blog Joined October 2009
United Kingdom371 Posts
September 24 2011 23:16 GMT
#1595
Anyone have any good resources on game networking?

I'm trying to make a multiplayer (hopefuly p2p via wifi) for the iphone.
DONATE SC2 BETA KEY TO ME PLEASE
Kambing
Profile Joined May 2010
United States1176 Posts
September 24 2011 23:30 GMT
#1596

Show nested quote +
* order of evaluation is still not defined
* too much "undefined behavior", a worthy standard should have exactly ZERO of these

I go back and forth on this. On one hand, I see where you're coming from, but on the other... compiler writers really can (and do) take advantage of that undefined behavior.


Precisely. Undefined behavior, while annoying in terms of interpreting the semantics of a language, can be critical for compiler optimizations. A handful of examples are in this LLVM blog post:

http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html

Another example are C++ STL iterators that provide very precise rules for when an iterator is invalidated, but makes the behavior undefined when those rules are broken. That way, library writers don't have to hamstring performance in the name of catching these points when behavior goes undefined.
Glowbox
Profile Joined June 2010
Netherlands330 Posts
Last Edited: 2011-09-24 23:40:38
September 24 2011 23:39 GMT
#1597
On September 25 2011 08:13 Frosticles wrote:
Hey guys Im working on a program in c++ to output the weekly salary of employees but for some reason when I input the hours, it is giving me these ridiculous answers. Possibly the problem lies in the declaration of variables? im not sure.

+ Show Spoiler +

#include <iostream>
using namespace std;

int main ()
{
double hours;
double overtime;
double salary;
salary = (8 * hours);


cout << "Input the amount of hours worked: " <<endl;
cin >> hours;

if(hours<=40)
cout << "Your weekly salary is " << salary << " dollars" <<endl;

else if(hours>40)
cout << "Your weekly salaray is " << overtime << " dollars" << endl;


return 0;

}





You can't declare salary like that. You do 'salary = 8 * hours', but hours does not have a value yet at that point so salary will have weird values. Only after you get your hours input you can calculate the salary.
uZr
Profile Joined April 2011
20 Posts
September 24 2011 23:51 GMT
#1598
On September 25 2011 08:39 Glowbox wrote:
Show nested quote +
On September 25 2011 08:13 Frosticles wrote:
Hey guys Im working on a program in c++ to output the weekly salary of employees but for some reason when I input the hours, it is giving me these ridiculous answers. Possibly the problem lies in the declaration of variables? im not sure.

+ Show Spoiler +

#include <iostream>
using namespace std;

int main ()
{
double hours;
double overtime;
double salary;
salary = (8 * hours);


cout << "Input the amount of hours worked: " <<endl;
cin >> hours;

if(hours<=40)
cout << "Your weekly salary is " << salary << " dollars" <<endl;

else if(hours>40)
cout << "Your weekly salaray is " << overtime << " dollars" << endl;


return 0;

}





You can't declare salary like that. You do 'salary = 8 * hours', but hours does not have a value yet at that point so salary will have weird values. Only after you get your hours input you can calculate the salary.

To be even more accurate, you declare some double which are stored on the stack, but don't initialize them. So you end up with whatever was on the stack at that place at runtime as value for salary/hours/...
Last but not the least, you compute the value of salary before receiving the value of hours. C(++) doesn't do symbolic calculi. When performing assignment (=), it just evaluates the right operand and assign the result to the left one.
To explain that in another way, if salary(h) is the function giving the salary for given hours, you cannot calculate salary before knowing the value of h. Same goes for any computation in C, pay attention to the order of your different "=" operators.
heishe
Profile Blog Joined June 2009
Germany2284 Posts
September 25 2011 00:06 GMT
#1599
On September 23 2011 18:48 tISL wrote:
Hey,

I've recently started programming XNA games. Followed a amount of tutorials and have some contacts that help me with small problems.

However, anyone can recommend me a book regarding XNA? I read some stuff on the web there are no decent books and you just have 'to do it'. I'm not really a fan of non-stop following tutorials. I like to read the proces and everything related to XNA by learning from a book.

Any help?


I can personally recommend "Microsfot XNA Game Studio 3.0 Unleashed" ( http://www.amazon.co.uk/Microsoft-XNA-Game-Studio-Unleashed/dp/0672330229/ref=sr_1_1?ie=UTF8&qid=1316909078&sr=8-1 ). It basically covers the entire framework from beginning to end.

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.
mmp
Profile Blog Joined April 2009
United States2130 Posts
Last Edited: 2011-09-25 00:57:13
September 25 2011 00:35 GMT
#1600
Just as a reminder, you shouldn't post in this thread asking for direct answers to your homework. You won't learn well that way. Ask specific questions about things that genuinely confuse you after thinking about them.

I'll start us off (although it's not "homework"). I've read and understand http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf subsection 10.4.3 Entering Function Code, item (1), but I don't understand what purpose this serves the language in the bigger picture. For example, if I create an anonymous function and don't explicitly bind a context, the thisArg comes out as undefined -- which a lot of programmers I think assume "inherits" from lexical scope much like any variable (the nearest scope entry that is non-undefined wins). Any ideas on why this is the way it is? Does this make the language cleaner, so that there are fewer mistakes due to context-ambiguity? Are there any positive benefits of this (gives the programmer a tool, rather than just constraining sloppy code)?

+ Show Spoiler +
I think it is security-related.
I (λ (foo) (and (<3 foo) ( T_T foo) (RAGE foo) )) Starcraft
Prev 1 78 79 80 81 82 1032 Next
Please log in or register to reply.
Live Events Refresh
IPSL
17:00
Ro16 Group D
ZZZero vs rasowy
Napoleon vs KameZerg
Liquipedia
PSISTORM Gaming Misc
15:55
FSL teamleague CNvsASH, ASHvRR
Freeedom38
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Railgan 184
IndyStarCraft 110
BRAT_OK 47
MindelVK 29
EmSc Tv 13
StarCraft: Brood War
Britney 25290
Calm 2532
Shuttle 775
Stork 341
firebathero 288
Dewaltoss 113
Barracks 68
Mong 61
Rock 43
Shine 18
Dota 2
Gorgc5830
qojqva1713
Dendi963
Counter-Strike
ScreaM1084
byalli378
Heroes of the Storm
Khaldor535
Liquid`Hasu237
Other Games
Beastyqt573
DeMusliM291
Hui .222
Fuzer 215
Lowko213
Trikslyr46
CadenZie18
Organizations
Dota 2
PGL Dota 2 - Main Stream8971
Other Games
EGCTV625
gamesdonequick359
StarCraft 2
angryscii 24
EmSc Tv 13
EmSc2Tv 13
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 22 non-featured ]
StarCraft 2
• HappyZerGling 71
• HeavenSC 61
• printf 5
• LaughNgamezSOOP
• sooper7s
• AfreecaTV YouTube
• Migwel
• intothetv
• Kozan
• IndyKCrew
StarCraft: Brood War
• Airneanach42
• HerbMon 6
• Michael_bg 3
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• C_a_k_e 2455
• WagamamaTV359
• Ler79
League of Legends
• Nemesis2825
Other Games
• imaqtpie1125
• Shiphtur313
Upcoming Events
OSC
45m
davetesta15
BSL 21
1h 45m
Tarson vs Julia
Doodle vs OldBoy
eOnzErG vs WolFix
StRyKeR vs Aeternum
Sparkling Tuna Cup
15h 45m
RSL Revival
15h 45m
Reynor vs sOs
Maru vs Ryung
Kung Fu Cup
17h 45m
Cure vs herO
Reynor vs TBD
WardiTV Korean Royale
17h 45m
BSL 21
1d 1h
JDConan vs Semih
Dragon vs Dienmax
Tech vs NewOcean
TerrOr vs Artosis
IPSL
1d 1h
Dewalt vs WolFix
eOnzErG vs Bonyth
Replay Cast
1d 4h
Wardi Open
1d 17h
[ Show More ]
Monday Night Weeklies
1d 22h
WardiTV Korean Royale
2 days
BSL: GosuLeague
3 days
The PondCast
3 days
Replay Cast
4 days
RSL Revival
4 days
BSL: GosuLeague
5 days
RSL Revival
5 days
WardiTV Korean Royale
5 days
RSL Revival
6 days
WardiTV Korean Royale
6 days
IPSL
6 days
Julia vs Artosis
JDConan vs DragOn
Liquipedia Results

Completed

Proleague 2025-11-14
Stellar Fest: Constellation Cup
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
BSL Season 21
CSCL: Masked Kings S3
SLON Tour Season 2
RSL Revival: Season 3
META Madness #9
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
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...

Disclosure: This page contains affiliate marketing links that support TLnet.

Advertising | Privacy Policy | Terms Of Use | Contact Us

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