Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 101 102 [103] 104 105 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 883023 times)

Sirus

  • Bay Watcher
  • Resident trucker/goddess/ex-president.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1530 on: February 17, 2012, 02:48:07 am »

'Cause I'm panicking because this thing is due in 10 minutes.

I want to program, dammit! What' wrong with me, why can't I get this?  :'(
Logged
Quote from: Max White
And lo! Sirus did drive his mighty party truck unto Vegas, and it was good.

Star Wars: Age of Rebellion OOC Thread

Shadow of the Demon Lord - OOC Thread - IC Thread

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1531 on: February 17, 2012, 02:50:25 am »

Relax. Logic is a cool, calm and collected thing. We also have a theory called GIGO, that means Garbage In = Garbage Out. It has a secondary, technical meaning, but who cares about that? The point of it is that if your mind is scattered and not logical, your code will be scattered and not logical. Zen the fuck out.

fergus

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1532 on: February 17, 2012, 02:53:29 am »

A pointer (e.g. float*) is the address of a piece of data. Dereferencing the pointer means going to that address and using whatever happens to be there.

Also, I just noticed that you didn't initialise you variables, leaving them in an undefined state (i.e. random garbage). I think the problem is that calculate is not setting the outside copy of the variable, leaving them undefined. There might also be something funny going on with scanf.

EDIT: Put printf statements before and after each function call for every variable it's supposed to modify. That should help narrow it down.

EDIT 2: OK, scanf is supposed to take pointers, so that part should be fine.
« Last Edit: February 17, 2012, 02:57:04 am by fergus »
Logged
BY THE GODS! THIS QUOTE MADE MY SIG BOX HAVE A SCROLL BAR! HAPPY DAYS INDEED!
BY THE GODS! YOU HAVE TOO MANY SIGS!

Xegeth

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1533 on: February 17, 2012, 02:59:12 am »

Maybe try posting the code you have now. I'd guess one problem is that calculate is not working as it should. You need to dereference each pointer in calculate, which means looking at the value pointed. Try something like this (and remember to update the declaration if you changed it).

Code: [Select]
void calculate(float* subTotal, int* quantity, float* unitPrice, float* discountAm, float* discountRate, float* subTaxable, float* taxAm, float* total)
{
//Calculations
(*subTotal)    =(*quantity) * (*unitPrice);
(*discountAm)  = (*subTotal) * (*discountRate) / 100.0;
(*subTaxable)  = (*subTotal) - (*discountAm);
(*taxAm) = (*subTaxable) * TAX_RATE/ 100.00;
(*total) = (*subTaxable) + (*taxAm);

return;
}
Logged

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1534 on: February 17, 2012, 03:01:24 am »

Spoiler (click to show/hide)
Noise generator is looking good.

Sirus

  • Bay Watcher
  • Resident trucker/goddess/ex-president.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1535 on: February 17, 2012, 03:05:22 am »

I'll work on it more tomorrow, after a good night's sleep. I just submitted what I had. I'm thinking that a partial assignment is better than no assignment at all.

Here's the code I submitted:
Spoiler (click to show/hide)
And now, I think I will go to bed. Maybe inspiration will strike while I sleep; it's happened before.
Logged
Quote from: Max White
And lo! Sirus did drive his mighty party truck unto Vegas, and it was good.

Star Wars: Age of Rebellion OOC Thread

Shadow of the Demon Lord - OOC Thread - IC Thread

eerr

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1536 on: February 17, 2012, 03:11:20 am »

Spoiler (click to show/hide)
Pffft, you still need an immense increase in your pointer-fu. What are you gonna do, figure it all out in your sleep?
Logged

fergus

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1537 on: February 17, 2012, 03:14:37 am »

OK, I took a copy of the source code, and I think I got it working, so:
1:change
Code: [Select]
void calculate(float subTotal, int quantity, float unitPrice, float discountAm, float discountRate, float subTaxable, float taxAm, float total)
to
Code: [Select]
void calculate(float* subTotal, int* quantity, float* unitPrice, float* discountAm, float* discountRate, float* subTaxable, float* taxAm, float* total)
(the *'s make the variables into pointers

3:put * in-front of all variable references in calculate
i.e.:
Code: [Select]
*subTotal    = *quantity * *unitPrice;
*discountAm  = *subTotal * *discountRate / 100.0;
*subTaxable  = *subTotal - *discountAm;
*taxAm = *subTaxable * TAX_RATE/ 100.00;
*total = *subTaxable + *taxAm;
The *'s are dereferencing operators.

Also, what compiler are you using, mine(gcc) generated several errors when I tried to compile it.
Logged
BY THE GODS! THIS QUOTE MADE MY SIG BOX HAVE A SCROLL BAR! HAPPY DAYS INDEED!
BY THE GODS! YOU HAVE TOO MANY SIGS!

Sirus

  • Bay Watcher
  • Resident trucker/goddess/ex-president.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1538 on: February 17, 2012, 03:18:47 am »

Can't fucking sleep -_-

I'm using Microsoft Visual Studio 2010. Did your changes, build failed.
Logged
Quote from: Max White
And lo! Sirus did drive his mighty party truck unto Vegas, and it was good.

Star Wars: Age of Rebellion OOC Thread

Shadow of the Demon Lord - OOC Thread - IC Thread

fergus

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1539 on: February 17, 2012, 03:21:31 am »

Error message?

EDIT: This is the source I have open here:
Spoiler (click to show/hide)

Also, I made both of those changes + the "void outputData();" to "void outputData(int,float,float,float,float,float,float);" change from the source code you posed originally.
« Last Edit: February 17, 2012, 03:26:15 am by fergus »
Logged
BY THE GODS! THIS QUOTE MADE MY SIG BOX HAVE A SCROLL BAR! HAPPY DAYS INDEED!
BY THE GODS! YOU HAVE TOO MANY SIGS!

Sirus

  • Bay Watcher
  • Resident trucker/goddess/ex-president.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1540 on: February 17, 2012, 03:23:28 am »

There's a bunch of them, all located in the calculate statement.

'function' : cannot convert from 'float *' to 'float'
Logged
Quote from: Max White
And lo! Sirus did drive his mighty party truck unto Vegas, and it was good.

Star Wars: Age of Rebellion OOC Thread

Shadow of the Demon Lord - OOC Thread - IC Thread

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1541 on: February 17, 2012, 03:31:23 am »

Wonder if anyone here has any experience with this....
Looked into Lua like you, thought hey this could be fun, then went on to do different stuff.

So if you find anything, let us know and share your experience :)
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

MaximumZero

  • Bay Watcher
  • Stare into the abyss.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1542 on: February 17, 2012, 03:33:00 am »

So, I'm thinking about trying to become a lead designer for some games company. I'm not terribly good with code, as my posts will show, but I'm very creative and good with English. Is there a better/more suitable position for me, and if not, what should I focus on in my studies?
Logged
  
Holy crap, why did I not start watching One Punch Man earlier? This is the best thing.
probably figured an autobiography wouldn't be interesting

fergus

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1543 on: February 17, 2012, 03:37:31 am »

OK, I just used diff to check the changes I made to the original source you posted and got:
Spoiler (click to show/hide)

Alternatively, this is the code I have after these changes:
Code: [Select]
#include <stdio.h>

#define TAX_RATE 8.50

//Function Declarations
void getData(int*, float*, float*);
void calculate(float*, int*, float*, float*, float*, float*, float*, float*);
void outputData(int,float,float,float,float,float,float);

int main (void)
{
// Local Declarations
int    quantity;

float  discountRate;
float  discountAm;
float  unitPrice;
float  subTotal;
float  subTaxable;
float  taxAm;
float  total;

// Statements
getData(&quantity, &unitPrice, &discountRate);
calculate(&subTotal, &quantity, &unitPrice, &discountAm, &discountRate, &subTaxable, &taxAm, &total);
outputData(quantity, unitPrice, subTotal, discountAm, subTaxable, taxAm, total);

return 0;
} // main

void getData(int *quantity, float *unitPrice, float *discountRate)
{
//Statements
printf("\nEnter number of items sold:         ");
scanf("%d", &*quantity);

printf("Enter the unit price:               ");
scanf("%f", &*unitPrice);

printf("Enter the discount rate (per cent): ");
scanf("%f", &*discountRate);

return;
}

void calculate(float* subTotal, int* quantity, float* unitPrice, float* discountAm, float* discountRate, float* subTaxable, float* taxAm, float* total)
{
//Calculations
*subTotal    = *quantity * *unitPrice;
*discountAm  = *subTotal * *discountRate / 100.0;
*subTaxable  = *subTotal - *discountAm;
*taxAm = *subTaxable * TAX_RATE/ 100.00;
*total = *subTaxable + *taxAm;

return;
}

void outputData(int quantity, float unitPrice, float subTotal, float discountAm, float subTaxable, float taxAm, float total)
{
//Statements
printf("\nQuantity sold:       %6d\n", quantity);
printf("Unit Price of items: %9.2f\n", unitPrice);
printf("                     ------------\n");

printf("Subtotal :           %9.2f\n", subTotal);
printf("Discount:           -%9.2f\n", discountAm);
printf("Discounted total:    %9.2f\n", subTaxable);
printf("Sales tax:          +%9.2f\n", taxAm);
printf("Total sale:          %9.2f\n", total);
}
Does that compile?
Logged
BY THE GODS! THIS QUOTE MADE MY SIG BOX HAVE A SCROLL BAR! HAPPY DAYS INDEED!
BY THE GODS! YOU HAVE TOO MANY SIGS!

Sirus

  • Bay Watcher
  • Resident trucker/goddess/ex-president.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1544 on: February 17, 2012, 03:42:04 am »

It does  :o

Now I just need to figure out why and how this all works. Time for a textbook binge, I guess.
Logged
Quote from: Max White
And lo! Sirus did drive his mighty party truck unto Vegas, and it was good.

Star Wars: Age of Rebellion OOC Thread

Shadow of the Demon Lord - OOC Thread - IC Thread
Pages: 1 ... 101 102 [103] 104 105 ... 796