• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 10:29
CET 16:29
KST 00:29
  • 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
TL.net Map Contest #21: Winners11Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10[ASL20] Finals Preview: Arrival13TL.net Map Contest #21: Voting12[ASL20] Ro4 Preview: Descent11
Community News
[TLMC] Fall/Winter 2025 Ladder Map Rotation6Weekly 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
[TLMC] Fall/Winter 2025 Ladder Map Rotation Mech is the composition that needs teleportation t Weekly Cups (Nov 3-9): Clem Conquers in Canada Craziest Micro Moments Of All Time? SC: Evo Complete - Ranked Ladder OPEN ALPHA
Tourneys
Constellation Cup - Main Event - Stellar Fest Tenacious Turtle Tussle Sparkling Tuna Cup - Weekly Open Tournament $5,000+ WardiTV 2025 Championship Merivale 8 Open - LAN - Stellar Fest
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
BW General Discussion FlaSh on: Biggest Problem With SnOw's Playstyle Terran 1:35 12 Gas Optimization BGH Auto Balance -> http://bghmmr.eu/ [ASL20] Ask the mapmakers — Drop your questions
Tourneys
[BSL21] RO32 Group D - Sunday 21:00 CET [BSL21] RO32 Group C - Saturday 21:00 CET [ASL20] Grand Finals [Megathread] Daily Proleagues
Strategy
Current Meta PvZ map balance How to stay on top of macro? Soma's 9 hatch build from ASL Game 2
Other Games
General Games
EVE Corporation Nintendo Switch Thread Stormgate/Frost Giant Megathread Should offensive tower rushing be viable in RTS games? 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
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine Canadian Politics Mega-thread The Games Industry And ATVI
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
[Manga] One Piece Anime Discussion Thread Movie Discussion! 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: 1229 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 States17264 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
OSC
11:30
Mid Season Playoffs
Krystianer vs PercivalLIVE!
WardiTV1063
TKL 199
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
TKL 199
SteadfastSC 109
Rex 91
StarCraft: Brood War
Calm 3367
Bisu 2918
Rain 2430
Hyuk 1473
Horang2 984
Flash 514
Soma 498
Stork 393
Rush 303
Soulkey 121
[ Show more ]
Backho 114
Barracks 58
sas.Sziky 46
hero 38
Aegong 27
zelot 22
sSak 21
Terrorterran 20
Rock 19
Killer 16
Dota 2
Gorgc3152
qojqva2018
Dendi1105
BananaSlamJamma123
XcaliburYe100
Other Games
hiko638
Sick526
DeMusliM442
Hui .346
Fuzer 199
Mew2King94
QueenE50
Organizations
StarCraft: Brood War
Kim Chul Min (afreeca) 9
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 16 non-featured ]
StarCraft 2
• poizon28 22
• intothetv
• AfreecaTV YouTube
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• HerbMon 10
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• C_a_k_e 3021
• WagamamaTV453
League of Legends
• Nemesis4037
• TFBlade977
Upcoming Events
Tenacious Turtle Tussle
7h 31m
The PondCast
18h 31m
RSL Revival
18h 31m
Solar vs Zoun
MaxPax vs Bunny
Kung Fu Cup
20h 31m
WardiTV Korean Royale
20h 31m
PiGosaur Monday
1d 9h
RSL Revival
1d 18h
Classic vs Creator
Cure vs TriGGeR
Kung Fu Cup
1d 20h
CranKy Ducklings
2 days
RSL Revival
2 days
herO vs Gerald
ByuN vs SHIN
[ Show More ]
Kung Fu Cup
2 days
IPSL
3 days
ZZZero vs rasowy
Napoleon vs KameZerg
BSL 21
3 days
Tarson vs Julia
Doodle vs OldBoy
eOnzErG vs WolFix
StRyKeR vs Aeternum
Sparkling Tuna Cup
3 days
RSL Revival
3 days
Reynor vs sOs
Maru vs Ryung
Kung Fu Cup
3 days
WardiTV Korean Royale
3 days
BSL 21
4 days
JDConan vs Semih
Dragon vs Dienmax
Tech vs NewOcean
TerrOr vs Artosis
IPSL
4 days
Dewalt vs WolFix
eOnzErG vs Bonyth
Wardi Open
4 days
Monday Night Weeklies
5 days
WardiTV Korean Royale
5 days
The PondCast
6 days
Liquipedia Results

Completed

Proleague 2025-11-07
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
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
BLAST Open Fall Qual

Upcoming

SLON Tour Season 2
BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
RSL Revival: Season 3
META Madness #9
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...

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.