Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 20 21 [22] 23 24 ... 91

Author Topic: Programming Help Thread (For Dummies)  (Read 100664 times)

MaximumZero

  • Bay Watcher
  • Stare into the abyss.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #315 on: November 05, 2011, 11:10:01 pm »

I don't really understand references all that well, but I have a feeling that when I do, I will understand why The Toad made ampersands into demons.
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

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #316 on: November 09, 2011, 02:31:20 pm »

Anybody happen to know if python has something like the  ? : operator?  I keep wanting to have conditionals in my expressions but I'm not seeing a way to do it.
« Last Edit: November 09, 2011, 02:35:37 pm by Levi »
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Mephisto

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #317 on: November 09, 2011, 02:43:13 pm »

Anybody happen to know if python has something like the  ? : operator?  I keep wanting to have conditionals in my expressions but I'm not seeing a way to do it.

Kind of. Check out the FAQ which, while for Python 2.x, is also valid for 3.x,

or Pep 308, which discusses why Python is different in this regard.
Logged

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #318 on: November 09, 2011, 02:45:48 pm »

Anybody happen to know if python has something like the  ? : operator?  I keep wanting to have conditionals in my expressions but I'm not seeing a way to do it.

Kind of. Check out the FAQ which, while for Python 2.x, is also valid for 3.x,

or Pep 308, which discusses why Python is different in this regard.

Perfect, that is good enough for me.  Thanks!
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #319 on: November 16, 2011, 05:10:13 am »

Ok guys, the language is Java, and the problem is Keyboard input. I imagine this is common enough for somebody to have covered it, but some quick research turns over nothing.
I want something that will wait for keyboard input, then return a single character without use of a console. Something along these lines...

Code: [Select]
Keyboard keyboard = new Keyboard();
char input = keyboard.getChar();

Or using a static class would also be good, I see no reason why not. Either way, anything out there?

Jopax

  • Bay Watcher
  • Cat on a hat
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #320 on: November 16, 2011, 08:54:10 am »

Righto, homework help time.
Working in C++ right now and one of the problems we have to solve is a program that takes three real numbers from the user input and then sorts them by size, we can only use the IF command to do so (no loops or anything).Now I don't need the whole solution, just how should I approach this since I have no idea in which way I could utilize the IF commands in order to compare all the numbers and then write them out without making it incredibly huge and convulted.
Logged
"my batteries are low and it's getting dark"
AS - IG

Darvi

  • Bay Watcher
  • <Cript> Darvi is my wifi.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #321 on: November 16, 2011, 08:57:24 am »

Similar problem here. Gotta find the biggest number out of three using C.

I have never worked with C before. It's close enough to C++ that I can actually write something, but different enough for not to work at all.

Oh, and we don't have a compiler yet so we gotta do it on notepad.

Fun.
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #322 on: November 16, 2011, 09:42:15 am »

Righto, homework help time.
Working in C++ right now and one of the problems we have to solve is a program that takes three real numbers from the user input and then sorts them by size, we can only use the IF command to do so (no loops or anything).Now I don't need the whole solution, just how should I approach this since I have no idea in which way I could utilize the IF commands in order to compare all the numbers and then write them out without making it incredibly huge and convulted.
You just first compare 2 numbers, store them in the right order, then compare the third value first to the highest of the two and then if needed to the lowest. That should tell you where to put it relative to the two already stored values.
Note: Writing it out like this for values larger than 4 is going to hurt your head (not to mention your hands), but the pattern is regular, so you could just write a compiler macro to handle it for you. also the comparison of val 3 would probably more elegantly handled with a case statement.
« Last Edit: November 16, 2011, 09:46:21 am by Virex »
Logged

Mephisto

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #323 on: November 16, 2011, 10:43:24 am »

Ok guys, the language is Java, and the problem is Keyboard input. I imagine this is common enough for somebody to have covered it, but some quick research turns over nothing.
I want something that will wait for keyboard input, then return a single character without use of a console. Something along these lines...

Code: [Select]
Keyboard keyboard = new Keyboard();
char input = keyboard.getChar();

Or using a static class would also be good, I see no reason why not. Either way, anything out there?

I was a little unsure myself, so with a bit of Googling: Reading input character by character
Logged

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: Programming Help Thread (For Dummies)
« Reply #324 on: November 16, 2011, 11:03:08 am »

Ok guys, the language is Java, and the problem is Keyboard input. I imagine this is common enough for somebody to have covered it, but some quick research turns over nothing.
I want something that will wait for keyboard input, then return a single character without use of a console. Something along these lines...

Code: [Select]
Keyboard keyboard = new Keyboard();
char input = keyboard.getChar();

Or using a static class would also be good, I see no reason why not. Either way, anything out there?

Off the top of my head, you can create a gui text box, set its focus and either loop through with a read and purge of its value or wait for a keydown event.
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

Jopax

  • Bay Watcher
  • Cat on a hat
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #325 on: November 16, 2011, 12:29:59 pm »

Solved it, took quite a while since i kept coming up with new possibilities that had to be accounted for X)

Thanks a bunch for the help :)
Logged
"my batteries are low and it's getting dark"
AS - IG

MaximumZero

  • Bay Watcher
  • Stare into the abyss.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #326 on: November 16, 2011, 12:53:58 pm »

Speaking of homework, I seem to be stuck.

Language: Visual Basic
Mission (should you choose to accept it): Take a variable on one form, put it in a second form, and keep it around after the first form closes.
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

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #327 on: November 16, 2011, 02:56:25 pm »

I don't know visual basic at all, but can't you just copy the variable by value and stow it away somewhere safe?
Logged

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: Programming Help Thread (For Dummies)
« Reply #328 on: November 16, 2011, 03:07:33 pm »

The form definition is just a class. The Form in the application is just an object. Add a public member to the form definition of form 2 and set it from form 1.

Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

Darvi

  • Bay Watcher
  • <Cript> Darvi is my wifi.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #329 on: November 23, 2011, 02:39:03 pm »

There seems to be a problem in my code when it comes to assigning values to an array of integers. Instead of the intended rand()%100 I get crazy values like -1216353508 -1078954956 -1078954948 -163754450
Code: [Select]
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>

void sort (int a[]){
   int unsorted = 0;
   do{
      unsorted = 0;   
      for (int i = 0; i < 20; i++){   
         if (*(a+i)>*(a+i+1)){
            int t = *(a+i+1);
            *(a+i+1) = *(a+i);
            *(a+i) = t;
            unsorted = 1;
            }   
         }         
      }while(unsorted);
}

int main(){
===========================
   int l1 = 5, l2 = 5, l3 = l1 + l2, t1[l1], t2[l2], t3[l3];
   srand(time(NULL));
   for (int i = 0; i < l2; i++){*(t2+i) = rand()%100;};
   for (int i = 0; i < l1; i++){*(t1+i) = rand()%100;};
   sort(t1);
   sort(t2);
===========================
   int i = 0, j = 0;
   while ((i < l1)&&(j < l2)){
      if (*(t1+i) < *(t2+j)){
         *(t3+i+j) = *(t1+i);
         i++;
      }else{
         *(t3+i+j) = *(t2+j);
         j++;
      }
   }
   while (i < l1){
      *(t3+i+j) = *(t1+i);
      i++;
   }
   while (j < l2){
      *(t3+i+j) = *(t2+j);
      j++;
   }
   for (int k = 0; k < l3; k++){printf("%d ",*(t3+k));}
   printf("\n");
   return 0;
}

The troublemaker's the t2 array but I'm too lazy incapable of noticing any mistake.
The bit between the equal signs is the part where I assume the problem is because I tried the code with the rest commented out but the problem still remaining.

E: Welp it appears that the sorting function seems to be the cause of the mistake. Gotta fix that.
« Last Edit: November 23, 2011, 02:47:50 pm by Darvi »
Logged
Pages: 1 ... 20 21 [22] 23 24 ... 91