this is all very well and good but does anyone know why its stuck on 45 or 44? Unless its just me, in which case tell me if everything is working fine
this is all very well and good but does anyone know why its stuck on 45 or 44? Unless its just me, in which case tell me if everything is working fine
>i only just got the post and haven't got round to doing it yet
Well, when you get around to doing it you can feel free to ask for more help. We don't like endless threads trying to get someone to fix an obvious error.
>isn't that what i put?
No, what you actually put was what I quoted.
>this is all very well and good but does anyone know why its stuck on 45 or 44?
Did you fix all of the errors and warnings? Because once I do that your code works just peachy in Dev-C++.
My best code is written with the delete key.
um, i've fixed all those problems (i think) but its still not doing what i want, whenever i try to withdraw cash or cheques the answer always comes out to 45.00, why!?!?
the code has being uploaded (again)
http://petedeeuk.8bit.co.uk/wtf.jpg
oh and why do windows close when the code is finished and how do i stop it?
Last edited by petedee; 01-06-2004 at 03:54 PM.
>why!?!?
I can't help you with a problem I can't reproduce.
>the code has being uploaded (again)
Here is the code I have been using that works properly on both Dev-C++ and VC++. Does it match yours?
Code:#include <stdio.h> float deposited (float); float withdrawn (float); int main() { int menu_choice = 0; int transactions = 0; float balance = 0; while (menu_choice != 4) { printf ("Your current balance = %.2f \n", balance); printf ("1. Deposit funds \n"); printf ("2. Withdraw funds \n"); printf ("3. Show balance \n"); printf ("4. Quit Program \n"); printf ("Please select what you wish to do (1-4): \n"); scanf ("%d", &menu_choice); switch (menu_choice) { case 1: printf ("1. Deposit funds \n"); balance = deposited (balance); transactions ++; break; case 2: printf ("2. Withdraw funds \n"); balance = withdrawn (balance); break; case 3: printf ("3. Show balance \n"); printf ("Your current balance = %.2f \n", balance); break; case 4: printf ("Exiting... \n"); break; default: printf("Please Enter a Choice from 1-4\n" ); break; } } return 0; } float deposited (float balance) { float deposit; printf ("Please enter how much you wish to deposit \n"); scanf ("%f", &deposit); if ((deposit + balance < 999999) || (deposit + balance > 0)) { balance = balance + deposit; printf ("Thank you %.2f has been entered into your account\n", deposit); } else printf ("I'm sorry but the number you have entered out of range/n"); return (balance); } float withdrawn (float balance) { float cashwithdraw, chequewithdraw; int transtype; printf ("Please enter how you wish to withdraw \n"); printf ("1. Cash \n"); printf ("2. Cheque\n"); scanf ("%d", &transtype); switch (transtype) { case 1: printf ("How much would you like to withdraw? \n"); scanf ("%f", &cashwithdraw); balance = balance - cashwithdraw; printf ("%.2f has being withdrawn from your account \n", cashwithdraw); break; case 2: printf ("How much would you like to withdraw? (maximum of 500) \n"); scanf ("%f", &chequewithdraw); if (chequewithdraw > 500) printf ("You are limited to a maximum of 500 \n"); else if (chequewithdraw < 0) printf ("Please enter a positive number \n"); else { printf ("%.2f has being withdrawn from your account \n", chequewithdraw); balance = balance - chequewithdraw; } break; default: printf("Please Enter a Choice from either 1 or 2\n" ); break; } return (balance); }
My best code is written with the delete key.
Okay, here is the code that i am using completed thus far, this is as up-to-date as i have:
The bug is:Code:#include <stdio.h> float deposited (float); float withdawn (float); int main() { int menu_choice = 0; float deposit = 0; float withdraw = 0; int transactions = 0; float balance = 0; float nodeposits = 0; float total_deposited = 0; float wibble; while (menu_choice != 4) { printf ("Your current balance = %.2f \n", balance); printf ("1. Deposit funds \n"); printf ("2. Withdraw funds \n"); printf ("3. Show balance \n"); printf ("4. Quit Program \n"); printf ("Please select what you wish to do (1-4): \n"); scanf ("%d", &menu_choice); switch (menu_choice) { case 1: printf ("1. Deposit funds \n"); balance = deposited (balance); transactions ++; break; case 2: printf ("2. Withdraw funds \n"); balance = withdrawn (balance, &total_deposited); nodeposits ++; break; case 3: printf ("3. Show balance \n"); printf ("Your current balance = %.2f \n", balance); break; case 4: printf ("Exiting... \n"); printf ("closing balance.............%.2f \n", balance); printf ("completed transactions......%.2f \n", transactions); printf (" /n"); printf ("completed deposits..........%.2f \n", nodeposits); break; default: printf("Please Enter a Choice from 1-4\n" ); break; } } return 0; } float deposited (float balance) { float deposit = 0; printf ("Please enter how much you wish to deposit \n"); scanf ("%f", &deposit); if ((deposit + balance < 999999) || (deposit + balance > 0)) { balance = balance + deposit; printf ("Thank you %.2f has been entered into your account\n", deposit); } else printf ("I'm sorry but the number you have entered out of range/n"); return (balance); } float withdrawn (float balance) { float cashwithdraw = 0, chequewithdraw = 0; int transtype; printf ("Please enter how you wish to withdraw \n"); printf ("1. Cash \n"); printf ("2. Cheque\n"); scanf ("%d", &transtype); switch (transtype) { case 1: { printf ("How much would you like to withdraw? \n"); scanf ("%f", &cashwithdraw); balance = balance - cashwithdraw; printf ("%.2f has being withdrawn from your account \n", cashwithdraw); break; } case 2: { printf ("How much would you like to withdraw? (maximum of 500) \n"); scanf ("%f", &chequewithdraw); if ((chequewithdraw > 500) || (chequewithdraw < 0)) printf ("You are limited to a maximum of 500 \n"); { printf ("%.2f has being withdrawn from your account \n", chequewithdraw); balance = balance - chequewithdraw; } break; default: printf("Please Enter a Choice from either 1 or 2\n" ); break; } } return (balance); }
Start the program
Select option 1. deposit funds
Enter an amount
Select option 2. withdraw funds
select option 1. cash
imput a number
The screen will display: "your current balance is 45.00" regardless of how much you put in or take out
please tell me this is just my computer going funny
>please tell me this is just my computer going funny
No, it's you ignoring our help. I get three warnings with Dev-C++ and the code you gave in your most recent post, they all had to do with the fact that your prototype doesn't match the definition; a problem we informed you of in every reply since the beginning of this thread I might add. You also call it with one too many arguements.
There's sound you'll hear often when you ignore people's help, let me give you a sample.
*plonk*
My best code is written with the delete key.
Honest to god, I'm really not ignoring your help, I'm really trying to see what is wrong with my code,
You are saying there are errors with the prototype and the definition:
prototype:
definition:Code:float deposited (float); float withdrawn (float);
I'm not being ignorant but i just don't see any problems with them unless I'm understanding somthing wrongly. I am honestly not ignoring your help, I just don't understand what you mean.Code:float withdrawn (float balance)
I don't get any, i've unticked everything in the C/C++ compiler options tab in the compiler options.I get three warnings with Dev-C++
Check your spelling in the post containing the code:
>>float withdawn (float);
Then you call withdrawn like this:
>>balance = withdrawn (balance, &total_deposited);
That has two parameters, but the function only takes one.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Yea, but thats an old piece of code that has being fixed in the new posts, the quotes in my latest post are what is in the code now and it still doesn't want to work
So paste the latest code, directly from your editor, along with any compiler error/warning messages and a description of what's wrong.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
just for you:
Code:#include <stdio.h> float deposited (float); float withdawn (float); int main() { int menu_choice = 0; float deposit = 0; float withdraw = 0; int transactions = 0; float balance = 0; float nodeposits = 0; float total_deposited = 0; float wibble; while (menu_choice != 4) { printf ("Your current balance = %.2f \n", balance); printf ("1. Deposit funds \n"); printf ("2. Withdraw funds \n"); printf ("3. Show balance \n"); printf ("4. Quit Program \n"); printf ("Please select what you wish to do (1-4): \n"); scanf ("%d", &menu_choice); switch (menu_choice) { case 1: printf ("1. Deposit funds \n"); balance = deposited (balance); transactions ++; break; case 2: printf ("2. Withdraw funds \n"); balance = withdrawn (balance, &total_deposited); nodeposits ++; break; case 3: printf ("3. Show balance \n"); printf ("Your current balance = %.2f \n", balance); break; case 4: printf ("Exiting... \n"); printf ("closing balance.............%.2f \n", balance); printf ("completed transactions......%.2f \n", transactions); printf (" /n"); printf ("completed deposits..........%.2f \n", nodeposits); break; default: printf("Please Enter a Choice from 1-4\n" ); break; } } return 0; } float deposited (float balance) { float deposit = 0; printf ("Please enter how much you wish to deposit \n"); scanf ("%f", &deposit); if ((deposit + balance < 999999) || (deposit + balance > 0)) { balance = balance + deposit; printf ("Thank you %.2f has been entered into your account\n", deposit); } else printf ("I'm sorry but the number you have entered out of range/n"); return (balance); } float withdrawn (float balance) { float cashwithdraw = 0, chequewithdraw = 0; int transtype; printf ("Please enter how you wish to withdraw \n"); printf ("1. Cash \n"); printf ("2. Cheque\n"); scanf ("%d", &transtype); switch (transtype) { case 1: { printf ("How much would you like to withdraw? \n"); scanf ("%f", &cashwithdraw); balance = balance - cashwithdraw; printf ("%.2f has being withdrawn from your account \n", cashwithdraw); break; } case 2: { printf ("How much would you like to withdraw? (maximum of 500) \n"); scanf ("%f", &chequewithdraw); if ((chequewithdraw > 500) || (chequewithdraw < 0)) printf ("You are limited to a maximum of 500 \n"); { printf ("%.2f has being withdrawn from your account \n", chequewithdraw); balance = balance - chequewithdraw; } break; default: printf("Please Enter a Choice from either 1 or 2\n" ); break; } } return (balance); }
That STILL has the spelling mistake in it. It's on the third line of code, you can't miss it
It also has the other errors I mentioned.
You didn't even post the compiler messages or give an explanation of what's wrong, like I asked you to. If you want help, you have to play the game..
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
oh dear god, i honestly cannot belive i missed that!! If someone had just said line 3 of the code i would of found it, thank you, i really feel daft now
Anyway, i would have assumed you would seen the
thing i said above, but with all the code on this page its easy to miss.The bug is:
Start the program
Select option 1. deposit funds
Enter an amount
Select option 2. withdraw funds
select option 1. cash
imput a number
The screen will display: "your current balance is 45.00" regardless of how much you put in or take out
I can't belive how thick i am, you guys must think I'm a right dumbass and i completely agree with you.
I guess with this sorted then everything is fixed, there is one last thing that i need to do (count the amount deposited) but i should be able to do that on my own.
i hope.
Lessee here.Originally posted by petedeeCode:#include <stdio.h> float deposited (float balance) { float deposit = 0; printf ("Please enter how much you wish to deposit \n"); scanf ("%f", &deposit); if ((deposit + balance < 999999) || (deposit + balance > 0)) { balance = balance + deposit; printf ("Thank you %.2f has been entered into your account\n", deposit); } else printf ("I'm sorry but the number you have entered out of range/n"); return (balance); }
If deposit + balance = 200, then
if ((200 < 999999) || (200 > 0))
Both comparisons are true, statement is true
If deposit + balance = -200, then
if ((-200 < 999999) || (200 > 0))
First comparison is true, therefore the statement is true
If deposit + balance = 2000000, then
if ((2000000 < 999999) || (2000000 > 0))
Second comparison is true, therefore the statement is true
When is it false?
Has anyone mentioned the danger of using scanf()? Search the board for reasons why scanf() is not a good function to use and for alternatives. I'll bet you're not reading the stream correctly.Originally posted by petedeeCode:float withdrawn (float balance) { float cashwithdraw = 0, chequewithdraw = 0; int transtype; printf ("Please enter how you wish to withdraw \n"); printf ("1. Cash \n"); printf ("2. Cheque\n"); scanf ("%d", &transtype); switch (transtype) { case 1: { printf ("How much would you like to withdraw? \n"); scanf ("%f", &cashwithdraw); balance = balance - cashwithdraw; printf ("%.2f has being withdrawn from your account \n", cashwithdraw); is this print statement the one that claims 45.00? break; } case 2: { printf ("How much would you like to withdraw? (maximum of 500) \n"); scanf ("%f", &chequewithdraw); if ((chequewithdraw > 500) || (chequewithdraw < 0)) printf ("You are limited to a maximum of 500 \n"); { printf ("%.2f has being withdrawn from your account \n", chequewithdraw); balance = balance - chequewithdraw; } break; default: printf("Please Enter a Choice from either 1 or 2\n" ); break; } } return (balance); }
Also see this link
Definition: Politics -- Latin, from
poly meaning many and
tics meaning blood sucking parasites
-- Tom Smothers