• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 05:40
CET 11:40
KST 19:40
  • 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
ByuL: The Forgotten Master of ZvT25Behind the Blue - Team Liquid History Book17Clem wins HomeStory Cup 289HomeStory Cup 28 - Info & Preview13Rongyi Cup S3 - Preview & Info8
Community News
Weekly Cups (Feb 9-15): herO doubles up2ACS replaced by "ASL Season Open" - Starts 21/0241LiuLi Cup: 2025 Grand Finals (Feb 10-16)46Weekly Cups (Feb 2-8): Classic, Solar, MaxPax win2Nexon's StarCraft game could be FPS, led by UMS maker16
StarCraft 2
General
Behind the Blue - Team Liquid History Book ByuL: The Forgotten Master of ZvT Liquipedia WCS Portal Launched Kaelaris on the futue of SC2 and much more... How do you think the 5.0.15 balance patch (Oct 2025) for StarCraft II has affected the game?
Tourneys
PIG STY FESTIVAL 7.0! (19 Feb - 1 Mar) Sparkling Tuna Cup - Weekly Open Tournament StarCraft Evolution League (SC Evo Biweekly) How do the "codes" work in GSL? LiuLi Cup: 2025 Grand Finals (Feb 10-16)
Strategy
Custom Maps
Map Editor closed ? [A] Starcraft Sound Mod
External Content
Mutation # 514 Ulnar New Year The PondCast: SC2 News & Results Mutation # 513 Attrition Warfare Mutation # 512 Overclocked
Brood War
General
Do you consider PvZ imbalanced? A new season just kicks off A cwal.gg Extension - Easily keep track of anyone Recent recommended BW games BGH Auto Balance -> http://bghmmr.eu/
Tourneys
Escore Tournament StarCraft Season 1 [Megathread] Daily Proleagues Small VOD Thread 2.0 KCM Race Survival 2026 Season 1
Strategy
Simple Questions, Simple Answers Zealot bombing is no longer popular? Fighting Spirit mining rates Current Meta
Other Games
General Games
Nintendo Switch Thread New broswer game : STG-World Battle Aces/David Kim RTS Megathread Diablo 2 thread ZeroSpace Megathread
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
Mafia Game Mode Feedback/Ideas Vanilla Mini Mafia TL Mafia Community Thread
Community
General
US Politics Mega-thread Mexico's Drug War Russo-Ukrainian War Thread Canadian Politics Mega-thread Ask and answer stupid questions here!
Fan Clubs
The IdrA Fan Club The herO Fan Club!
Media & Entertainment
[Req][Books] Good Fantasy/SciFi books [Manga] One Piece Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion TL MMA Pick'em Pool 2013
World Cup 2022
Tech Support
TL Community
The Automated Ban List
Blogs
ASL S21 English Commentary…
namkraft
Inside the Communication of …
TrAiDoS
My 2025 Magic: The Gathering…
DARKING
Life Update and thoughts.
FuDDx
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2169 users

The Big Programming Thread - Page 85

Forum Index > General Forum
Post a Reply
Prev 1 83 84 85 86 87 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.
mmp
Profile Blog Joined April 2009
United States2130 Posts
October 11 2011 22:51 GMT
#1681
Use the [code] forum tag to get verbatim indentation.
I (λ (foo) (and (<3 foo) ( T_T foo) (RAGE foo) )) Starcraft
Quasimomo
Profile Joined October 2011
Netherlands4 Posts
October 11 2011 23:08 GMT
#1682
On October 12 2011 07:47 Ripense wrote:
Show nested quote +
On October 12 2011 07:17 Quasimomo wrote:
Derp! Of course hahaha xD

Here is the whole code that's causing the problems ( I think )
I'm working with a few other .java files. These include the GUI file and the file that takes care of linking vlc to java.

+ Show Spoiler +

package businessunits;

import com.phidgets.*;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;



public class BusinessUnitsApp extends SingleFrameApplication {

@Override protected void startup() {
show(new BusinessUnitsView(this));
}

/**
* This method is to initialize the specified window by injecting resources.
* Windows shown in our application come fully initialized from the GUI
* builder, so this additional configuration is not needed.
*/
@Override protected void configureWindow(java.awt.Window root) {
}

/**
* A convenient static getter for the application instance.
* @return the instance of BusinessUnitsApp
*/
public static BusinessUnitsApp getApplication() {
return Application.getInstance(BusinessUnitsApp.class);
}

/**
* Main method launching the application.
*/

VLCv2 vlc = new VLCv2("localhost", 1234);
private Phidget phidget;
private BusinessUnitsView guiobj;
private InterfaceKitPhidget interf;

/**
* constructor van deze Main klasse, maak GUI aan en
* maak verbinding met VLC
*/


public long getsensor(int a) {
long sensor = readSensorValue(a);

return sensor;
}

public boolean getdeurbel() {
boolean deurbel = Inputstate(0);
return deurbel;

}

//Vanaf 120
public long StartMove() {

long sensor7 = readSensorValue(7);
return sensor7;

}

public boolean deurbel() {
while (true) {
try {
boolean deurbel = Inputstate(0);
Thread.sleep(250);
System.out.println(deurbel);
if (deurbel) {
return deurbel;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

public static void main(String[] args) throws InterruptedException {

launch(BusinessUnitsApp.class, args);

BusinessUnitsApp m = new BusinessUnitsApp();
VLCv2 vlc = new VLCv2("localhost", 1234);

vlc.connect();
vlc.rc.fullscreen();
vlc.rc.play();
vlc.rc.pause();

while (true) {
try {

Robot rob = new Robot();
Thread.sleep(250);
long sensor7 = m.StartMove();


if (sensor7 >= 70) {
vlc.rc.play();

for (int i = 0; i <= 110; i++) {
Thread.sleep(1000);
System.out.println(i);
if (i == 110) {
vlc.rc.pause();
}
}
}

if (m.getsensor(0) < 100) {
rob.mouseMove(1550, 340);
rob.mousePress(InputEvent.BUTTON1_MASK);
rob.mouseRelease(InputEvent.BUTTON1_MASK);

}

if (m.getsensor(1) < 100) {
rob.mouseMove(1550, 410);
rob.mousePress(InputEvent.BUTTON1_MASK);
rob.mouseRelease(InputEvent.BUTTON1_MASK);

}

if (m.getsensor(2) < 100) {
rob.mouseMove(1550, 470);
rob.mousePress(InputEvent.BUTTON1_MASK);
rob.mouseRelease(InputEvent.BUTTON1_MASK);

}

if (m.getsensor(3) < 100) {
rob.mouseMove(1550, 535);
rob.mousePress(InputEvent.BUTTON1_MASK);
rob.mouseRelease(InputEvent.BUTTON1_MASK);

}

if (m.getsensor(4) < 100) {
rob.mouseMove(1550, 600);
rob.mousePress(InputEvent.BUTTON1_MASK);
rob.mouseRelease(InputEvent.BUTTON1_MASK);

}

if (m.getsensor(5) < 100) {
rob.mouseMove(1550, 650);
rob.mousePress(InputEvent.BUTTON1_MASK);
rob.mouseRelease(InputEvent.BUTTON1_MASK);

}

if (m.getdeurbel()) {
vlc.rc.play();

for (int a = 0; a <= 126; a++) {
Thread.sleep(1000);
System.out.print(a + " ");

if (a == 44) {
vlc.rc.pause();
while (true) {
try {
boolean deurbel = m.deurbel();
if (deurbel == true) {
vlc.rc.play();
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
if (a == 126){
vlc.rc.pause();
}
}

}

} catch (AWTException e) {
e.printStackTrace();
}
}
}


public void makeConnection() {

try {
//interf.openAny("localhost", 5001); // alleen voor webservice-versie
interf.openAny(); // werkt ook zonder webservice
interf.waitForAttachment(1000); // 1 sec, anders exception
} catch (PhidgetException e) {
e.printStackTrace();
}
}// end of phidgetmakeConnection()
//public native boolean getInputState(int i) throws PhidgetException;

public boolean Inputstate(int nr) {
boolean value = false;
try {
value = interf.getInputState(nr);
} catch (PhidgetException e) {
e.printStackTrace();
}
return value;

}

public long readSensorValue(int nr) {
long value = -1;
try {
value = interf.getSensorValue(nr);
} catch (PhidgetException e) {
e.printStackTrace();
}
return value;
}

public void setOutputValue(int nr, Boolean state) {
try {
interf.setOutputState(nr, state);
} catch (PhidgetException e) {
e.printStackTrace();
}
}
}




As far as I can see you call the method getSensorValue on the interf variable which is no initialized and therefore throws a NullpointerException. You need to do something like inter = new InterfaceKitPhidget(); before calling methods on it.


I'm glad you see what's wrong with it :D
but... could you perhaps explain in more detail please? I've only been working with java for a couple of weeks so I don't really know where look for things and where to put them =(
Keitzer
Profile Blog Joined May 2010
United States2509 Posts
October 12 2011 02:56 GMT
#1683
anyone know how to call the b2Vec2 function Multiply(a:number:void in Objective-C++? Been bugging me all day since I can't find out how
I'm like badass squared | KeitZer.489
Ripense
Profile Joined August 2010
Austria23 Posts
October 12 2011 11:55 GMT
#1684
On October 12 2011 08:08 Quasimomo wrote:
Show nested quote +
On October 12 2011 07:47 Ripense wrote:
On October 12 2011 07:17 Quasimomo wrote:
Derp! Of course hahaha xD

Here is the whole code that's causing the problems ( I think )
I'm working with a few other .java files. These include the GUI file and the file that takes care of linking vlc to java.

+ Show Spoiler +


package businessunits;

import com.phidgets.*;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;



public class BusinessUnitsApp extends SingleFrameApplication {

@Override protected void startup() {
show(new BusinessUnitsView(this));
}

/**
* This method is to initialize the specified window by injecting resources.
* Windows shown in our application come fully initialized from the GUI
* builder, so this additional configuration is not needed.
*/
@Override protected void configureWindow(java.awt.Window root) {
}

/**
* A convenient static getter for the application instance.
* @return the instance of BusinessUnitsApp
*/
public static BusinessUnitsApp getApplication() {
return Application.getInstance(BusinessUnitsApp.class);
}

/**
* Main method launching the application.
*/

VLCv2 vlc = new VLCv2("localhost", 1234);
private Phidget phidget;
private BusinessUnitsView guiobj;
private InterfaceKitPhidget interf;

/**
* constructor van deze Main klasse, maak GUI aan en
* maak verbinding met VLC
*/


public long getsensor(int a) {
long sensor = readSensorValue(a);

return sensor;
}

public boolean getdeurbel() {
boolean deurbel = Inputstate(0);
return deurbel;

}

//Vanaf 120
public long StartMove() {

long sensor7 = readSensorValue(7);
return sensor7;

}

public boolean deurbel() {
while (true) {
try {
boolean deurbel = Inputstate(0);
Thread.sleep(250);
System.out.println(deurbel);
if (deurbel) {
return deurbel;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

public static void main(String[] args) throws InterruptedException {

launch(BusinessUnitsApp.class, args);

BusinessUnitsApp m = new BusinessUnitsApp();
VLCv2 vlc = new VLCv2("localhost", 1234);

vlc.connect();
vlc.rc.fullscreen();
vlc.rc.play();
vlc.rc.pause();

while (true) {
try {

Robot rob = new Robot();
Thread.sleep(250);
long sensor7 = m.StartMove();


if (sensor7 >= 70) {
vlc.rc.play();

for (int i = 0; i <= 110; i++) {
Thread.sleep(1000);
System.out.println(i);
if (i == 110) {
vlc.rc.pause();
}
}
}

if (m.getsensor(0) < 100) {
rob.mouseMove(1550, 340);
rob.mousePress(InputEvent.BUTTON1_MASK);
rob.mouseRelease(InputEvent.BUTTON1_MASK);

}

if (m.getsensor(1) < 100) {
rob.mouseMove(1550, 410);
rob.mousePress(InputEvent.BUTTON1_MASK);
rob.mouseRelease(InputEvent.BUTTON1_MASK);

}

if (m.getsensor(2) < 100) {
rob.mouseMove(1550, 470);
rob.mousePress(InputEvent.BUTTON1_MASK);
rob.mouseRelease(InputEvent.BUTTON1_MASK);

}

if (m.getsensor(3) < 100) {
rob.mouseMove(1550, 535);
rob.mousePress(InputEvent.BUTTON1_MASK);
rob.mouseRelease(InputEvent.BUTTON1_MASK);

}

if (m.getsensor(4) < 100) {
rob.mouseMove(1550, 600);
rob.mousePress(InputEvent.BUTTON1_MASK);
rob.mouseRelease(InputEvent.BUTTON1_MASK);

}

if (m.getsensor(5) < 100) {
rob.mouseMove(1550, 650);
rob.mousePress(InputEvent.BUTTON1_MASK);
rob.mouseRelease(InputEvent.BUTTON1_MASK);

}

if (m.getdeurbel()) {
vlc.rc.play();

for (int a = 0; a <= 126; a++) {
Thread.sleep(1000);
System.out.print(a + " ");

if (a == 44) {
vlc.rc.pause();
while (true) {
try {
boolean deurbel = m.deurbel();
if (deurbel == true) {
vlc.rc.play();
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
if (a == 126){
vlc.rc.pause();
}
}

}

} catch (AWTException e) {
e.printStackTrace();
}
}
}


public void makeConnection() {

try {
//interf.openAny("localhost", 5001); // alleen voor webservice-versie
interf.openAny(); // werkt ook zonder webservice
interf.waitForAttachment(1000); // 1 sec, anders exception
} catch (PhidgetException e) {
e.printStackTrace();
}
}// end of phidgetmakeConnection()
//public native boolean getInputState(int i) throws PhidgetException;

public boolean Inputstate(int nr) {
boolean value = false;
try {
value = interf.getInputState(nr);
} catch (PhidgetException e) {
e.printStackTrace();
}
return value;

}

public long readSensorValue(int nr) {
long value = -1;
try {
value = interf.getSensorValue(nr);
} catch (PhidgetException e) {
e.printStackTrace();
}
return value;
}

public void setOutputValue(int nr, Boolean state) {
try {
interf.setOutputState(nr, state);
} catch (PhidgetException e) {
e.printStackTrace();
}
}
}





As far as I can see you call the method getSensorValue on the interf variable which is no initialized and therefore throws a NullpointerException. You need to do something like inter = new InterfaceKitPhidget(); before calling methods on it.


I'm glad you see what's wrong with it :D
but... could you perhaps explain in more detail please? I've only been working with java for a couple of weeks so I don't really know where look for things and where to put them =(



VLCv2 vlc = new VLCv2("localhost", 1234);
private Phidget phidget;
private BusinessUnitsView guiobj;
private InterfaceKitPhidget interf;


In this part you declare some variables. The declaration alone does not assign an object to the variable. For the variable vlc you assign an object (new VLCv2("localhost", 1234). However the other variables are still null. At some point in you code you need to have the other variables on the left side of an assign operation before you use them otherwise, or the will still be null. That's what I think is the problem, because at


public long readSensorValue(int nr) {
long value = -1;
try {
value = interf.getSensorValue(nr);
} catch (PhidgetException e) {
e.printStackTrace();
}
return value;
}


you call the function getSensorValue(int) on the interf variable, but this variable is still null (not defined) as there isn't a point in the code, where interf is assigned an object. Similar to your vlc variable you need to assign an object to the interf variable before calling the method. Depending on your code this could be as easy as assigning the object during declaration as you did with the vlc variable


private InterfaceKitPhidget interf = new InterfaceKitPhidget();


See the following code snippet for a simplified version of the problem in your code. Analog to your readSensorValue method in this case the testproc method throws a NullPointerException, because the String variable a is not defined.


public class test {
static String a;

/**
* @param args
*/
public static void main(String[] args) {
testproc();
}

public static void testproc() {
a.length();
}
}


I hope this clarifies my earlier statement. To avoid such problems, always make sure, that a value or object is assigned to your variables before using them.
KaiserJohan
Profile Joined May 2010
Sweden1808 Posts
October 12 2011 16:45 GMT
#1685
I need to make a really quick and simple website. What is the best tool available?
I am talking about making a website that takes between 1-2 hours from scratch at most. Drag-and-drop stuff which then produces a .html document would be sweet.
England will fight to the last American
Butterednuts
Profile Blog Joined September 2010
United States859 Posts
October 12 2011 16:55 GMT
#1686
On October 13 2011 01:45 KaiserJohan wrote:
I need to make a really quick and simple website. What is the best tool available?
I am talking about making a website that takes between 1-2 hours from scratch at most. Drag-and-drop stuff which then produces a .html document would be sweet.


Wordpress offers pretty good starting points, where you can change it almost entirely from a blog to anything you want.
Chameleons Cast No Shadows
Necosarius
Profile Blog Joined September 2009
Sweden4042 Posts
October 12 2011 16:58 GMT
#1687
I have a hard time understanding recursion. Could someone please explain what it is/what it does?
KaiserJohan
Profile Joined May 2010
Sweden1808 Posts
October 12 2011 17:08 GMT
#1688
On October 13 2011 01:55 Butterednuts wrote:
Show nested quote +
On October 13 2011 01:45 KaiserJohan wrote:
I need to make a really quick and simple website. What is the best tool available?
I am talking about making a website that takes between 1-2 hours from scratch at most. Drag-and-drop stuff which then produces a .html document would be sweet.


Wordpress offers pretty good starting points, where you can change it almost entirely from a blog to anything you want.


Is there any other tools that you can work with offline?
England will fight to the last American
Frigo
Profile Joined August 2009
Hungary1023 Posts
Last Edited: 2011-10-12 17:19:30
October 12 2011 17:14 GMT
#1689
On October 13 2011 01:58 Necosarius wrote:
I have a hard time understanding recursion. Could someone please explain what it is/what it does?

A recursive function might call itself with different parameters to compute its return value, that's all.

For example, factorial calculation:
public class Main
{

public static void main (String[] args)
{
System.out.println(factorial(5));
}

public static int factorial (int n)
{
if( n == 0 ){
return 1;
}
return n * factorial(n - 1);
}

}


Another common example, calculating the Fibonacci number:
public class Main
{

public static void main (final String[] args)
{
System.out.println(fibonacci(7));
}

public static int fibonacci (int n)
{
if( n == 0 ){
return 0;
}
if( n == 1 ){
return 1;
}
return fibonacci(n - 1) + fibonacci(n - 2);
}

}

http://www.fimfiction.net/user/Treasure_Chest
Millitron
Profile Blog Joined August 2010
United States2611 Posts
October 12 2011 20:49 GMT
#1690
On October 13 2011 01:58 Necosarius wrote:
I have a hard time understanding recursion. Could someone please explain what it is/what it does?

Recursion is a general idea for creating methods. A recursive method has a simple answer for some base case, and calls itself for any other cases. The recursive calls generally try to whittle the problem down to a base case, then merge the returns of each call.

The Fibonacci and the factorial example, while being relatively easy to understand, are computationally very slow. There are much faster algorithms that don't use recursion.
Who called in the fleet?
killa_robot
Profile Joined May 2010
Canada1884 Posts
Last Edited: 2011-10-12 22:01:25
October 12 2011 22:00 GMT
#1691
On October 13 2011 01:58 Necosarius wrote:
I have a hard time understanding recursion. Could someone please explain what it is/what it does?



Recursion just means a method calls itself until it reaches some sort predetermined value. In this case, the method calls itself until it reaches zero. Since it calls itself there's only ever one of it, so it's static.



public class Main
{

public static void main (final String[] args)
{
GetToZero(7);
}

public static void GetToZero (int n)
{
if(n == 0)
{
System.out.println("Reached Zero");
}
else if (n > 0)
{
System.out.println("Subtracting 1 - " + n);
n--;
GetToZero(n);
}
else if (n < 0)
{
System.out.println("Adding 1 - " + n);
n++;
GetToZero(n);
}
}
}
Kambing
Profile Joined May 2010
United States1176 Posts
October 12 2011 22:28 GMT
#1692
On October 13 2011 01:58 Necosarius wrote:
I have a hard time understanding recursion. Could someone please explain what it is/what it does?


First thing to recognize: programming is problem solving by decomposition. Given a problem, you decompose that problem repeatedly into smaller problems until the subproblems are manageable to solve on their own. For example, the problem of cooking spaghetti involves several subtasks such as buying the ingredients, preparing the sauce, preparing the meat, and the mixing it all together. In code, you typically use functions/methods to realize this decomposition, e.g.,


void cookSpaghetti() {
buyIngredients();
prepareSauce();
prepareMeat();
mixIngredients();
}


With that in mind, recursion is a problem solving technique in which you recognize that the subproblems that you create are actually smaller versions of the original problem that you are trying to solve.

To make this more concrete, imagine a line of folk waiting for the release of heart of swarm:


front <(^^)> <(^^)> <(^^)> back


Now imagine that the person in the back of line is trying to figure out what place they are in line. One thing they can do is step out of line and count the number of people in front of them directly. However, instead of risking losing their place in line, they can ask the person in front of them:


front <(^^)> <(^^)> <(^^)> back
|-- "What place are you in line?"


Now, the person in front of them is posed with a similar question, so they can ask the person in front of them the same question:


front <(^^)> <(^^)> <(^^)> back
| |-- "What place are you in line?"
|-- "What place are you in line?"



Finally the question is posed to the person in the front of the line. He's know he's #1, so he tells the person behind him.


front <(^^)> <(^^)> <(^^)> back
| | |-- "What place are you in line?"
1 |-- "What place are you in line?"


With that answer, the person behind the first in line now knows what place they are in line. They know they're second by adding one to the place of the person in front of them.


front <(^^)> <(^^)> <(^^)> back
| | |-- "What place are you in line?"
1 2


And finally the person in the back knows their place in line given the position of the person in front of them by adding one.


front <(^^)> <(^^)> <(^^)> back
| | |
1 2 3


This is the essence of simple recursion:

  • A base case that handles the situation when the problem we're trying to solve is directly solvable.
  • A recursive case that solves the current problem by solving an identical subproblem of a smaller size.


Let's extend this to a code example that people have mentioned already, factorial(n).


int factorial(int n) {
// Base case, i.e., front of the line: 0! = 1
if (n <= 0) {
return 1;
// Recursive case, i.e., the middle or the line: n! = n * (n-1)!
} else {
return n * factorial(n-1);
}
}
Frosticles
Profile Joined May 2010
United States50 Posts
Last Edited: 2011-10-13 01:30:27
October 13 2011 01:24 GMT
#1693
I'm having a problem getting this chunk of code to work, I cannot seem to get the array from function int main() to pass correctly to int show()...

The compile has no problem with it, but for some reason it is not outputting anything.
Please point out my mistake.

+ Show Spoiler +

#include <iostream>
using namespace std;

const int MAXELS = 9;
void show(int [MAXELS]);

int main ()
{
double temps[MAXELS] = {6.5, 7.2, 7.5, 8.3, 8.6, 9.4, 9.6, 9.8, 10.0};

return 0;
}

void show(int temps[MAXELS])
{
int i;
for (i = 0; i < MAXELS; i = (i + 1))

cout << temps[i] << endl;

return;

}






NEVERMIND FOUND MY ERROR!!! :DD
Frigo
Profile Joined August 2009
Hungary1023 Posts
October 13 2011 05:47 GMT
#1694
Well you don't call show from main.
http://www.fimfiction.net/user/Treasure_Chest
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2011-10-13 06:13:50
October 13 2011 05:59 GMT
#1695
Yay! I finally have a use for this thread. Taking a Computer Science course in C (C++ next term ^^).

All the numbers to be entered will have two decimal places, and the total of the numbers entered won't be greater than 1 000 000.00 . I have to split this total into equal parts and print out the integer total and the cents since this is formatting for money.

My problem is that the precision of the numbers is really terrible so entering 999 999.99 three times and dividing it equally gives me 999 999.98 for some reason. I'm using double which is supposed to be more precise than float... so I'm confused when stuff like this comes out.

Any suggestions on how to preserve precision when working with large decimal numbers?

I'm also outputting with printf and %f. It's not very clear to me what's the best way to output decimal numbers or store them.
There is no one like you in the universe.
EvanED
Profile Joined October 2009
United States111 Posts
Last Edited: 2011-10-13 06:25:47
October 13 2011 06:25 GMT
#1696
Very simply. Never use floating point numbers (doubles count) for money. :-)

(I'm not really kidding either. That really is something that basically no one should ever do.)
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2011-10-13 08:21:36
October 13 2011 08:16 GMT
#1697
On October 13 2011 15:25 EvanED wrote:
Very simply. Never use floating point numbers (doubles count) for money. :-)

(I'm not really kidding either. That really is something that basically no one should ever do.)


What should I use for money then? The input has two decimal places... ?

I don't remember getting these kinds of errors in Python, but I'm using C now, and the lesson is supposed to be learning how to deal with the doubles I think...
There is no one like you in the universe.
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
October 13 2011 08:38 GMT
#1698
On October 13 2011 17:16 Blisse wrote:
Show nested quote +
On October 13 2011 15:25 EvanED wrote:
Very simply. Never use floating point numbers (doubles count) for money. :-)

(I'm not really kidding either. That really is something that basically no one should ever do.)


What should I use for money then? The input has two decimal places... ?

I don't remember getting these kinds of errors in Python, but I'm using C now, and the lesson is supposed to be learning how to deal with the doubles I think...


Floating point numbers have problems with precision. On the first look they work, but then you end up having customers pay only 0.99 cent instead of 1 euro.

For money you have to use a fixed point type (or in C you usually calculate with cents instead of euros/dollars) as they have exact instead of approximate representations.
Sky
Profile Blog Joined July 2004
Jordan812 Posts
October 13 2011 12:07 GMT
#1699
Dennis Ritchie dies at age 70.

A quote from another forum:

#include <stdio.h>

int main(void){
printf("goodbye world :( \n");
return(70);
}


each of us has a return value, but only very few of us are able to know what the return value we pass back is when our run-time ends and we hand ourselves over to the system.

-TheFloorIsNowBacon


...jumping into cold water whenever I get the chance.
Craton
Profile Blog Joined December 2009
United States17278 Posts
October 13 2011 16:47 GMT
#1700
Monetary institutions do track decimals beyond the hundredths place in transaction. The best way is to use a variable that actually has precision and then display it by formatting however is appropriate to the organization (I'm not really sure if they truncate or round, tbh).
twitch.tv/cratonz
Prev 1 83 84 85 86 87 1032 Next
Please log in or register to reply.
Live Events Refresh
Replay Cast
09:00
PiGosaur Cup #65
CranKy Ducklings154
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
SortOf 216
MindelVK 21
StarCraft: Brood War
Calm 4370
Sea 3897
Jaedong 753
Zeus 356
Barracks 270
Rush 214
ZerO 213
Light 167
Pusan 153
Dewaltoss 106
[ Show more ]
JulyZerg 51
Mini 49
Killer 47
Hm[arnc] 31
Snow 31
Noble 24
soO 23
Dota 2
XaKoH 734
XcaliburYe122
League of Legends
Reynor82
Counter-Strike
byalli2354
olofmeister1585
Stewie2K1021
shoxiejesuss927
zeus738
m0e_tv624
allub377
edward67
Other Games
singsing881
B2W.Neo746
crisheroes263
NotJumperer15
ZerO(Twitch)12
Organizations
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 11 non-featured ]
StarCraft 2
• StrangeGG 75
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Upcoming Events
Wardi Open
1h 20m
Monday Night Weeklies
6h 20m
OSC
13h 20m
WardiTV Winter Champion…
1d 1h
Replay Cast
1d 22h
WardiTV Winter Champion…
2 days
The PondCast
2 days
Replay Cast
3 days
Korean StarCraft League
4 days
CranKy Ducklings
4 days
[ Show More ]
SC Evo Complete
5 days
Replay Cast
5 days
Sparkling Tuna Cup
5 days
uThermal 2v2 Circuit
6 days
Replay Cast
6 days
Liquipedia Results

Completed

Proleague 2026-02-22
LiuLi Cup: 2025 Grand Finals
Underdog Cup #3

Ongoing

KCM Race Survival 2026 Season 1
Acropolis #4 - TS5
WardiTV Winter 2026
PiG Sty Festival 7.0
Nations Cup 2026
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
SL Budapest Major 2025

Upcoming

Jeongseon Sooper Cup
Spring Cup 2026
[S:21] ASL SEASON OPEN 2nd Round
[S:21] ASL SEASON OPEN 2nd Round Qualifier
Acropolis #4 - TS6
Acropolis #4
IPSL Spring 2026
HSC XXIX
uThermal 2v2 2026 Main Event
Bellum Gens Elite Stara Zagora 2026
RSL Revival: Season 4
PGL Astana 2026
BLAST Rivals Spring 2026
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
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.