• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 00:47
CET 06:47
KST 14:47
  • 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 Revival - 2025 Season Finals Preview8RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12
Community News
Weekly Cups (Dec 15-21): Classic wins big, MaxPax & Clem take weeklies3ComeBackTV's documentary on Byun's Career !11Weekly Cups (Dec 8-14): MaxPax, Clem, Cure win4Weekly Cups (Dec 1-7): Clem doubles, Solar gets over the hump1Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2
StarCraft 2
General
ComeBackTV's documentary on Byun's Career ! Team TLMC #5: Winners Announced! What's the best tug of war? The Grack before Christmas Weekly Cups (Dec 15-21): Classic wins big, MaxPax & Clem take weeklies
Tourneys
OSC Season 13 World Championship $5,000+ WardiTV 2025 Championship $100 Prize Pool - Winter Warp Gate Masters Showdow Sparkling Tuna Cup - Weekly Open Tournament Winter Warp Gate Amateur Showdown #1
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 505 Rise From Ashes Mutation # 504 Retribution Mutation # 503 Fowl Play Mutation # 502 Negative Reinforcement
Brood War
General
BW General Discussion How soO Began His ProGaming Dreams Klaucher discontinued / in-game color settings BGH Auto Balance -> http://bghmmr.eu/ Recommended FPV games (post-KeSPA)
Tourneys
[Megathread] Daily Proleagues [BSL21] LB SemiFinals - Saturday 21:00 CET [BSL21] WB & LB Finals - Sunday 21:00 CET Small VOD Thread 2.0
Strategy
Simple Questions, Simple Answers Game Theory for Starcraft Current Meta Fighting Spirit mining rates
Other Games
General Games
Nintendo Switch Thread Mechabellum Stormgate/Frost Giant Megathread Beyond All Reason 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
Mafia Game Mode Feedback/Ideas Survivor II: The Amazon Sengoku Mafia TL Mafia Community Thread
Community
General
US Politics Mega-thread 12 Days of Starcraft The Games Industry And ATVI Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine
Fan Clubs
White-Ra Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece
Sports
2024 - 2026 Football Thread Formula 1 Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List TL+ Announced Where to ask questions and add stream?
Blogs
National Diversity: A Challe…
TrAiDoS
I decided to write a webnov…
DjKniteX
James Bond movies ranking - pa…
Topin
Thanks for the RSL
Hildegard
Saturation point
Uldridge
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1717 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 States17274 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
Next event in 4h 13m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
WinterStarcraft568
RuFF_SC2 232
NeuroSwarm 225
StarCraft: Brood War
actioN 1471
Shuttle 128
GoRush 22
eros_byul 0
League of Legends
JimRising 686
C9.Mang0447
Counter-Strike
minikerr48
Heroes of the Storm
Khaldor111
Other Games
summit1g7185
XaKoH 146
Organizations
Other Games
gamesdonequick1285
BasetradeTV81
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 19 non-featured ]
StarCraft 2
• practicex 31
• LaughNgamezSOOP
• sooper7s
• AfreecaTV YouTube
• intothetv
• Migwel
• Kozan
• IndyKCrew
StarCraft: Brood War
• Azhi_Dahaki37
• Diggity2
• Pr0nogo 2
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• masondota22222
League of Legends
• Rush1088
• Lourlo972
• Stunt459
Other Games
• Scarra1616
Upcoming Events
Sparkling Tuna Cup
4h 13m
Krystianer vs Classic
TriGGeR vs SKillous
Percival vs Ryung
ByuN vs Nicoract
OSC
12h 13m
BSL 21
14h 13m
Cross vs Dewalt
Replay Cast
1d 3h
Wardi Open
1d 6h
OSC
2 days
Solar vs MaxPax
ByuN vs Krystianer
Spirit vs TBD
OSC
5 days
Korean StarCraft League
5 days
OSC
6 days
OSC
6 days
Liquipedia Results

Completed

Escore Tournament S1: W1
WardiTV 2025
META Madness #9

Ongoing

C-Race Season 1
IPSL Winter 2025-26
BSL Season 21
CSL Season 19: Qualifier 2
eXTREMESLAND 2025
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025

Upcoming

CSL 2025 WINTER (S19)
Escore Tournament S1: W2
Escore Tournament S1: W3
BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
Big Gabe Cup #3
OSC Championship Season 13
Nations Cup 2026
ESL Pro League Season 23
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
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 © 2025 TLnet. All Rights Reserved.