Author Topic: The programming help thread!  (Read 2174 times)

offsidewing

  • Hero Member
  • *****
  • Posts: 631
Re: The programming help thread!
« Reply #30 on: June 07, 2007, 02:23:40 PM »
I'm hosting a sales meeting on Tuesday.  I was going to get you some advice, but now I'm not gunna.

Nya nya-nya nya nya nyaaaaa.  Yes even successful business types post on PCENGINEFX.COM!!!!!!

Kitsunexus

  • Hero Member
  • *****
  • Posts: 3911
Re: The programming help thread!
« Reply #31 on: June 07, 2007, 02:31:07 PM »
I'm hosting a sales meeting on Tuesday.  I was going to get you some advice, but now I'm not gunna.

Nya nya-nya nya nya nyaaaaa.  Yes even successful business types post on PCENGINEFX.COM!!!!!!

What exactly do you do? In like 5 days I'll be a Customer Care Representative for T-Mobile specializing in pre-paid activation. ^__^

/Sorry, I broke my promise. :(

offsidewing

  • Hero Member
  • *****
  • Posts: 631
Re: The programming help thread!
« Reply #32 on: June 07, 2007, 02:45:56 PM »
I'm pretty much a corporate locust, but in a good way.  Currently, I'm employed by a Supply Chain Conglomorant and I'm contracted to a major US automaker.  I'm a complex business practice problem solver.  If there's an underperforming operating group, they plug me in to make sense of it.  I don't hire and fire, I get people out of the "if it ain't broke.." and "it's not my job" mentality.  Before that I was an investment banker.  Before that an athlete type.  Before that I was a giant man-whore in college.  Before that I was one of two people in my huge high school to have a Turbo Grafx 16.

When I'm not dodging head hunters, I waste time on PCENGINEFX.COM instead of finishing a few written works.

Edit:  Oh, and I don't know a thing about forum posting etiquitte.  I thought this was spamming:

"Hey, I just broke up with my boyfriend and saw your profile.  I'm into 'rounder' guys, I wonder if you'd like to meet up for drinks sometime.  Email me at vixenchick@youthinkiamreal.com."
« Last Edit: June 07, 2007, 02:56:17 PM by offsidewing »

Dark Fact

  • Hero Member
  • *****
  • Posts: 1147
Re: The programming help thread!
« Reply #33 on: June 07, 2007, 04:34:23 PM »
Guys...seriously, no spamming.  I don't want to have to scroll through 3 or 4 posts about nothingness just to get to my answers from nat or someone else.  You're more than welcome to make up a new thread with all your silliness but let a guy have his spot, ok?

Sorry, but I don't see your library card on the books of Ys.  Now, RETURN THEM TO ME!!!

Kitsunexus

  • Hero Member
  • *****
  • Posts: 3911
Re: The programming help thread!
« Reply #34 on: June 08, 2007, 06:32:47 AM »
OMG USE THE PM SYSTEM GODDD U R SO ANNOYING AND I HAVE TOO MUCH SUGAR AND I THINK IM GONNA PUKE  :-#

Dark Fact

  • Hero Member
  • *****
  • Posts: 1147
Re: The programming help thread!
« Reply #35 on: June 10, 2007, 04:05:42 AM »
PM? This thread exists not only to help me out on programming problems but for anyone else who also wants similar programming help, hence why it's called "The programming help thread".  I don't need you to tell me how to ask for help, kthnx. 

Sorry, but I don't see your library card on the books of Ys.  Now, RETURN THEM TO ME!!!

Kitsunexus

  • Hero Member
  • *****
  • Posts: 3911
Re: The programming help thread!
« Reply #36 on: June 10, 2007, 07:11:18 AM »
That was a joke....


Anyway, I'm starting to learn Ruby (my first language to learn other than BASIC) so I'll probably use this threa dlegit from now on. ;)

Dark Fact

  • Hero Member
  • *****
  • Posts: 1147
Re: The programming help thread!
« Reply #37 on: June 11, 2007, 02:05:02 PM »
Thank you.  Now, back to business:

I've got a question that asks me to enter an integer, see if the integer is divisible by 6, and then display an appropriate message afterwards.  The coding was no problem.  The question on the other hand, is too generalized.  When it means "divisible by 6", does it mean getting a result that appears as a whole number and/or a real number?

Here's my code for the meat of the program:

Code: [Select]
for (int_count = EVEN; int_count <= int_prompt - int_prompt; int_count++)
        {
          if (int_prompt / DIVISIBILITY)
             printf("\nThe integer is divisible by 6.");
          else
             printf("\nThe integer is not divisible by 6.");
        }
DIVISIBILITY has been predefined as "6".  The result I get from the program has any number less than 6 be declared "not divisible" while any number equal to or greater than 6 declared "divisible".  Is this correct?


Sorry, but I don't see your library card on the books of Ys.  Now, RETURN THEM TO ME!!!

nat

  • Hero Member
  • *****
  • Posts: 7085
Re: The programming help thread!
« Reply #38 on: June 11, 2007, 04:34:59 PM »
I think I'd interpret the question to mean "Is the number evenly divisible by 6?"

I just can't see it any other way.

Assuming this, I don't think your program there does the job. If I understand you correctly, your code reports 1-5 as "not divisible" while 6 and up are "divisible". That's simply not correct if we're assuming what I'm assuming. 7 is not evenly divisible by 6. Neither is 8. Or 9.

Your program is simply checking the success of the (int_prompt / DIVISIBILITY) operation.

Let's change things around a little bit and use a modulus operator:

     if ( int_prompt % DIVISIBILITY == 0 )
          printf("\nHell yeah! We're cruisin' now!");
     else
          printf("\nYour number makes Nat a sad Panda.");


My C++ skills are a bit rusty but that looks right to me.

Dark Fact

  • Hero Member
  • *****
  • Posts: 1147
Re: The programming help thread!
« Reply #39 on: June 11, 2007, 05:59:36 PM »
Yeah, that did the trick. :) Modulus makes programs happy. :)

Sorry, but I don't see your library card on the books of Ys.  Now, RETURN THEM TO ME!!!

Dark Fact

  • Hero Member
  • *****
  • Posts: 1147
Re: The programming help thread!
« Reply #40 on: June 19, 2007, 03:45:45 PM »
New problem:

I have a program that requires me to check to see if the amount withdrawn from an account in regular cash withdrawals or checks exceeds the amount already present.  For instance, if I had $2000 in my account, deposited $1000, withdrew $3000 in cash, and another $3000 in checks, my closing balance would come to $-3000.

I have an if statement that checks to see if the closing balance falls below $0.00 and if it does, displays the amount that has exceeded.

However, for some strange reason, my program was able to display the amount a couple of times but afterwards, mysteriously stopped when I put a #define statement for "0.00".  Even when I tried to undo it, the statement still didn't appear.  Here's the code:

Code: [Select]
/* Prob 8-10
*  Created by Yuriy Mokriy
*/

#include <stdio.h>

#define ACCOUNT_LIMIT 0.00          /* The limit of the account between positive and negative balance */

main()
{
      int choice;                   /* The user's selected choice */
      float  opening_balance,       /* The opening account balance */
             total_deposit,         /* The total of all deposits */
             deposit,               /* The amount of the deposit */
             total_check,           /* The total of all checks */
             check,                 /* The amount of the check */
             total_withdrawal,      /* The total of all withdrawals */
             withdrawal,            /* The amount of the withdrawal */
             closing_balance;       /* The closing account balance */             
             
      /* Prompt the user for the opening balance */
     
      printf("Enter your opening account balance for the month: $");
      scanf("%f", &opening_balance);
     
      /* Display menu */
     
      printf("\n(D)Deposit");
      printf("\n(C)Check");
      printf("\n(W)Withdrawal");
      printf("\n(Q)Quit");
      printf("\nMake your selection: ");
      getchar();
      choice = getchar();
     
      /* Perform action based on choice */
     
      do 
      {
             if (choice == 'd' || choice == 'D')
             {
                  printf("\nEnter the amount of the deposit: $");
                  scanf("%f", &deposit);
                  total_deposit += deposit;
             }
             else if (choice == 'c' || choice == 'C')
             {
                  printf("\nEnter the amount of the check: $");
                  scanf("%f", &check);
                  total_check += check;
             }
             else if (choice == 'w' || choice == 'W')
             {
                  printf("\nEnter the amount of the withdrawal: $");
                  scanf("%f", &withdrawal);
                  total_withdrawal += withdrawal;
             }         
             else
                 printf("\nError.  You must select the following: ");
             
             printf("\n(D)Deposit");
             printf("\n(C)Check");
             printf("\n(W)Withdrawal");
             printf("\n(Q)Quit");
             printf("\nMake your selection: ");
             getchar();
             choice = getchar();
      } while (!(choice == 'q' || choice == 'Q'));
         
      /* Perform calculation */
     
      closing_balance = opening_balance + total_deposit - total_withdrawal - total_check;
     
      /* Check if account is overdrawn */
     
      if (closing_balance < ACCOUNT_LIMIT)
      {
         printf("\nWARNING: Your account has been overdrawn by $%.2f", closing_balance + ACCOUNT_LIMIT); 
         printf("\n");
      }
     
      /* Display totals */
     
      printf("\nOPENING BALANCE: $%.2f", opening_balance);
      printf("\nTOTAL DEPOSIT:   $%.2f", total_deposit);
      printf("\nTOTAL WITHDRAWAL:$%.2f", total_withdrawal);
      printf("\nTOTAL CHECKS:    $%.2f", total_check);
      printf("\n------------------------");
      printf("\nCLOSING BALANCE: $%.2f", closing_balance);
}
Can you figure out why the if statement that checks for the overdrawn amount in the account won't appear in my program? Because I'm just positively baffled here. :?

Another thing, the program instructions ask for me to display a warning at any time during the program a withdrawal or check results in a negative balance.  Does the program want me to check for an over withdrawal each time the check amount or cash withdrawal falls below $0.00 or does it have to be after the closing balance has been computed?

Take your time guys.  I think I said a mouthful. :P

Sorry, but I don't see your library card on the books of Ys.  Now, RETURN THEM TO ME!!!

nat

  • Hero Member
  • *****
  • Posts: 7085
Re: The programming help thread!
« Reply #41 on: June 19, 2007, 06:28:31 PM »
Is your tutorial a C or C++ tutorial? Not that it makes a whole lot of difference, but #DEFINE is relatively obsolete in C++. Even for C, your usage is not entirely correct.

#DEFINE is typically used to assign macros and boolean attributes to an identifier. It looks like you are thinking of #DEFINE as a way to assign a value to a variable, which it does not.

Forget #DEFINE. I try not to use #DEFINE at all unless absolutely necessary.

What your problem is here is that you are trying to compare a floating point (closing_balance) to an identifier. It's not going to printf that statement because that comparison will never be "true".

Delete the #DEFINE line and change your variable definitions to look as follows:

       float  opening_balance,       /* The opening account balance */
             total_deposit,         /* The total of all deposits */
             deposit,               /* The amount of the deposit */
             total_check,           /* The total of all checks */
             check,                 /* The amount of the check */
             total_withdrawal,      /* The total of all withdrawals */
             withdrawal,            /* The amount of the withdrawal */
             closing_balance,       /* The closing account balance */   
             nat_rules = 0.00;      /* Clearly, Nat is the man. */     
     


And of course, change all instances of "ACCOUNT_LIMIT" to "nat_rules".

Dark Fact

  • Hero Member
  • *****
  • Posts: 1147
Well, I'm a dumbass!
« Reply #42 on: June 20, 2007, 07:59:37 AM »
Okay, the problem with the overdrawn closing amount not appearing was a faux pas on my part.  I had another program earlier that used the same format but didn't need the overdrawn amount message to appear.  I just wound up  inadvertently running that previous program instead of the current one.

However, the question regarding where the overdrawn amount message needs to be displayed still stands.  Does it need to be displayed the moment the withdrawn or check amount goes below 0.00 or when the closing balance has been tabulated?

Sorry, but I don't see your library card on the books of Ys.  Now, RETURN THEM TO ME!!!

nat

  • Hero Member
  • *****
  • Posts: 7085
Re: The programming help thread!
« Reply #43 on: June 20, 2007, 08:09:29 AM »
I would say it needs to be displayed at the moment the balance goes negative, but that's a semantics issue.

Dark Fact

  • Hero Member
  • *****
  • Posts: 1147
Re: The programming help thread!
« Reply #44 on: June 20, 2007, 03:16:24 PM »
I thought as much.  I fixed the problem by creating a new variable called "account_balance" that assigns the opening balance to it as well as any deposits, withdrawals, or checks made.  I then cut and pasted the if statement that checks for overdrawn amounts into my while loop.  "account_balance" was used as a condition in the statement.  Finally, I assigned "account_balance" to "closing_balance" in order to display the closing balance amount in my program.

Thanks guys. :) I'll be back when I have another problem. :wink:

Sorry, but I don't see your library card on the books of Ys.  Now, RETURN THEM TO ME!!!