Log in

View Full Version : C++ visual studio 2010 : hellpppp



blackmica10
11-24-2010, 11:43 AM
i know its the shot in the dark on the forum but what the hell, i figure at least ONE of the asians on the board is a programmer:chuckle....so i have a programming class at school and the final project is to make an atm. the entire thing works except for option c: that states add interest into your account. a number is returned, but its an insane number. for example if i compound 500$ at 1 year for 5% it gives out like 803333 dollars.... so if anyones good at accounting and programming help?

code right now is :
if(m==1)
{
printf("you are in chequings");
printf("\nplease enter the amount of years you would like to compound for");
scanf("%f",&years);
printf("\nplease enter your interest rate");
scanf("%f",&interest);
if(newbalcheq>=5000)
{
for(i=1; i<= years*12; i=i++);
newbalance=((interest/12)*newbalcheq);
return(newbalance);
fflush(stdin);
getchar();
}

newbalcheq is the amount in the chequings account, and newbalance is SUPPOSE to be the amount of money your left with

steve220s
11-24-2010, 11:53 AM
I haven't programed in years, but it seems as though you're not dividing the interest (%) by 100 before multiplying with the number of years.

vanpatrick81
11-24-2010, 11:56 AM
This might be a stupid question. But are you compounding on an annual basis or on a monthly basis?

Iceman_F1
11-24-2010, 12:16 PM
Never done C++ but if I'm reading this right, you enter years which is 1...you enter interest rate which is 5...I'm not sure what your loop is looping through (I do VB not C++) but you have newbalance= interest/12*newbalcheq...so interest/12 = 0.416..that * 500 = 208 in interest alone? I agree with steve220s though...I believe you aren't taking the interest and / by 100 to get the % form...

hastiej
11-24-2010, 02:25 PM
Well first thing I see if your newbalchq is acutally listed as 5000, not 500... might explain the bloated number your getting. But I also have't used C++.. sorry man



i know its the shot in the dark on the forum but what the hell, i figure at least ONE of the asians on the board is a programmer:chuckle....so i have a programming class at school and the final project is to make an atm. the entire thing works except for option c: that states add interest into your account. a number is returned, but its an insane number. for example if i compound 500$ at 1 year for 5% it gives out like 803333 dollars.... so if anyones good at accounting and programming help?

code right now is :
if(m==1)
{
printf("you are in chequings");
printf("\nplease enter the amount of years you would like to compound for");
scanf("%f",&years);
printf("\nplease enter your interest rate");
scanf("%f",&interest);
if(newbalcheq>=5000)
{
for(i=1; i<= years*12; i=i++);
newbalance=((interest/12)*newbalcheq);
return(newbalance);
fflush(stdin);
getchar();
}

newbalcheq is the amount in the chequings account, and newbalance is SUPPOSE to be the amount of money your left with

prinsesa
11-24-2010, 02:45 PM
Can anyone help me with my Physics assignment?

SilentJay
11-24-2010, 02:45 PM
Ah memories... Wait, why is an ATM asking what interest rate to pay? :chuckle

If you ever end up working for an ATM manufacturer, let me know... "Interest rate? 1000000%."

SilentJay
11-24-2010, 02:46 PM
Can anyone help me with my Physics assignment?

Boo physics. Do my Stats, and i'll consider physics :chuckle

hastiej
11-24-2010, 02:48 PM
:hijack smiley


Can anyone help me with my Physics assignment?

Iceman_F1
11-24-2010, 02:50 PM
Ah memories... Wait, why is an ATM asking what interest rate to pay? :chuckle

If you ever end up working for an ATM manufacturer, let me know... "Interest rate? 1000000%."

Good question :chuckle

prinsesa
11-24-2010, 03:00 PM
Sorry to hijack the thread!!! lol

Iceman_F1
11-24-2010, 03:08 PM
In theory, I guess in a perfect vacuum, it could go faster than the speed of light...but how does it get to that speed in the first place? It starts off at a set speed, I would assume not faster than the speed of light, and the only way it could get to the speed is constant acceleration. But it doesn't have that...unless there was a massive amount of force/explosion that would trigger the movement of gas...and even then, it's hard to imagine anything that could propel gas to that speed...

Though I have no clue...just bored at work and this gives me something to type out lol

vanpatrick81
11-24-2010, 03:35 PM
well, for one the for loop will loop to number of years * 12 but because the loop is all to itself and its variables are not beings used anywhere else, its pretty much pointless.

i'm also not sure as to where you're getting 80333 from because if i run thru your calculation this is what i get
(5/12)*500 = 208.3333333

but if you do it like steve220s says where you need to divide the interest by 100 to convert it to actual decimal, you get
((5/100)/12)*500 = 2.0833333

XTOTHEL
11-24-2010, 04:30 PM
looks like you are assuming that the interest is compounded MONTHLY thus the "year*12" gets your number of months. The rate to compound PER MONTH = rate PER YEAR / 12. So when you do your loop it should be like so:

(for int x= 0; x < (year*12); x++){
newbalance = newbalance * (1+ rate-per-month)
}
print(newblance);

like people have said, if you take in the yearly interest as a percent, you need to divide by 100 and then divide by 12.

You can also look for a formula that calculates compound interest instead of using loops.

steve220s
11-24-2010, 04:51 PM
i know its the shot in the dark on the forum but what the hell, i figure at least ONE of the asians on the board is a programmer:chuckle....so i have a programming class at school and the final project is to make an atm. the entire thing works except for option c: that states add interest into your account. a number is returned, but its an insane number. for example if i compound 500$ at 1 year for 5% it gives out like 803333 dollars.... so if anyones good at accounting and programming help?

code right now is :
if(m==1)
{
printf("you are in chequings");
printf("\nplease enter the amount of years you would like to compound for");
scanf("%f",&years);
printf("\nplease enter your interest rate");
scanf("%f",&interest);
if(newbalcheq>=5000)
{
for(i=1; i<= years*12; i=i++);
newbalance=((interest/12)*newbalcheq);
return(newbalance);
fflush(stdin);
getchar();
}

newbalcheq is the amount in the chequings account, and newbalance is SUPPOSE to be the amount of money your left with

If you ask me, this is what your program should do:
Ask for the existing balance, set to existingbalance
Ask for the interest rate or define this value without asking the user to do so, set as rate
Ask for the amount of years of interest to add to the existing balance, set to years
Then,
newbalance = existingbalance * (1 + rate/100)^years
this will calculate the new balance at the end of x amount of years chosen by the user assuming the interest is only compounted once annually. Very simple system which isn't really representative of banks but whatev...
If you want to make the program a little better, ask for the amount of months rather than years. Than take the rate, divide by 12 (for the amount of months in a year) and then divide by 100 (because it's a percentage), the formula becomes:
newbalance = existingbalance * (1 + ((rate/12)/100))^months
This is essentially the same program but the interest is compounted monthly which is how banks work.
The program will essentially show the user what his balance would be after x months with a certain interest rate by starting with an initial principal chosen himself.

blackmica10
11-24-2010, 11:01 PM
thanks for all the help guys, and dont ask me why it adds interest in an atm lmao its the project. also the outline states that you must ask for years compounded but calaculate in months.

n00bMeiSter
11-26-2010, 11:46 AM
Kinda late, but did you get this fixed?
C++ is my bitch, even though I'm stuck doing crappy vb right now.

What is newbalancecheq declared as? int, float, double?

for(i=1; i<= years*12; i=i++);
this is doing absolutely nothing, save for incrementing i, but you never used i or the loop. waste of time and memory.

newbalance=((interest/12)*newbalcheq);
like everyone else has said, you need to turn rate into a yearly percentage, and then divide by 12 to get monthly. you also need to remember that every month, when you add the interest, the next month you need to be calculating interest on the new amount in chequing, not the original amount.

for(i=1; i<= years*12; i++)
{
newbal = newbal * (1+((rate/100)/12))
}

Also:
scanf("%f",&years);
should be using %d unless you are going to let the user enter 1.5 years. in which case you need to do extra calculations to turn, ie 1.2 years, into 14 months.

Iceman_F1
11-26-2010, 11:56 AM
Kinda late, but did you get this fixed?
C++ is my bitch, even though I'm stuck doing crappy vb right now.

What is newbalancecheq declared as? int, float, double?

for(i=1; i<= years*12; i=i++);
this is doing absolutely nothing, save for incrementing i, but you never used i or the loop. waste of time and memory.

newbalance=((interest/12)*newbalcheq);
like everyone else has said, you need to turn rate into a yearly percentage, and then divide by 12 to get monthly. you also need to remember that every month, when you add the interest, the next month you need to be calculating interest on the new amount in chequing, not the original amount.

for(i=1; i<= years*12; i++)
{
newbal = newbal * (1+((rate/100)/12))
}

Also:
scanf("%f",&years);
should be using %d unless you are going to let the user enter 1.5 years. in which case you need to do extra calculations to turn, ie 1.2 years, into 14 months.

Hey, nothing wrong with VB!

But as for the loop, maybe the code is larger than what he listed and he only listed the relevant info? I know I do that instead of listing all the code as there's no need to list everything that has nothing to do with the problem part.

Hopefully the advice helped you. Didn't realize this many people were programmers :chuckle

n00bMeiSter
11-26-2010, 12:19 PM
Hey, nothing wrong with VB!

But as for the loop, maybe the code is larger than what he listed and he only listed the relevant info? I know I do that instead of listing all the code as there's no need to list everything that has nothing to do with the problem part.

Hopefully the advice helped you. Didn't realize this many people were programmers :chuckle

That's like saying American is a language. It's just a bastardization of a real langauge! and for those who can't speak (read: program) lol (j/k) :P
VB has some nice ideas, I'll give it that much. But on a whole, it's just not powerful enough. If I can't volatile some ASM / machine language in, I might as well go feed the ducks :P (okay, so that's an extreme example).

VB just doesn't give me the same kind of control that c++ does. However, the OOP and OM heirarchy of VB is nice. And For Each is awesome.

Iceman_F1
11-26-2010, 12:30 PM
That's like saying American is a language. It's just a bastardization of a real langauge! and for those who can't speak (read: program) lol (j/k) :P
VB has some nice ideas, I'll give it that much. But on a whole, it's just not powerful enough. If I can't volatile some ASM / machine language in, I might as well go feed the ducks :P (okay, so that's an extreme example).

VB just doesn't give me the same kind of control that c++ does. However, the OOP and OM heirarchy of VB is nice. And For Each is awesome.

I guess VB works well enough for us then. I find no issues with it...then again never worked with C++ before so can't judge. We've done some interesting stuff in VB...guess it's whatever works for each person to do what you need to do.

n00bMeiSter
11-26-2010, 12:39 PM
I guess VB works well enough for us then. I find no issues with it...then again never worked with C++ before so can't judge. We've done some interesting stuff in VB...guess it's whatever works for each person to do what you need to do.

Yup, to each his own. What do you guys do with it? What interesting things have you guys managed to do with it?
If you're going to be interacting with Office products, for sure VB is probably your best bet. Or if you're in a huge hurry and only have time to basically drag and drop.

Iceman_F1
11-26-2010, 12:47 PM
Yup, to each his own. What do you guys do with it? What interesting things have you guys managed to do with it?
If you're going to be interacting with Office products, for sure VB is probably your best bet. Or if you're in a huge hurry and only have time to basically drag and drop.

Our main use is tracking info throughout the shop (Kitchen Manufacture)...so printing labels based on the cabinet info and such...but a couple years ago I had to develop a program for the person who does the measuring. He used to carry tons of papers with him to draw on as well as copies of the info (colours/style/house layout) for each job he was going to do each day. Which means each day we had to have someone print out all that for him. But with the help of an add-on called Infragistics (different GUI things that work a bit better than default VB stuff), we developed a program that he can call up info from our database, draw the kitchen with measurements, then submit it while on the road. Results in less paper for him and he can do a lot more on the road. Was kinda annoying to do what was basically a customized paint program...but at the same time, interesting to let it email, pull off our database and such.

n00bMeiSter
11-26-2010, 01:06 PM
Our main use is tracking info throughout the shop (Kitchen Manufacture)...so printing labels based on the cabinet info and such...but a couple years ago I had to develop a program for the person who does the measuring. He used to carry tons of papers with him to draw on as well as copies of the info (colours/style/house layout) for each job he was going to do each day. Which means each day we had to have someone print out all that for him. But with the help of an add-on called Infragistics (different GUI things that work a bit better than default VB stuff), we developed a program that he can call up info from our database, draw the kitchen with measurements, then submit it while on the road. Results in less paper for him and he can do a lot more on the road. Was kinda annoying to do what was basically a customized paint program...but at the same time, interesting to let it email, pull off our database and such.

Wow, that would work wonders with what I'm building.
I'm going to PM you, as to not hijack anymore.

Slade
11-26-2010, 01:21 PM
Perl > all

:P

I do a lot of data aggravation from routers, cli , rsh and perl are my tools of choice :)

n00bMeiSter
11-26-2010, 01:28 PM
Perl > all

:P

I do a lot of data aggravation from routers, cli , rsh and perl are my tools of choice :)

You can't build a video game in Perl :P

blackmica10
11-26-2010, 04:49 PM
wow programmers prescence is awesome here lol good thing i posted. thanks for the input noobmeister, except our prof doesnt want us using anything accept int float and char as its only first years programming. now i have another question for you here. this is a compound interest formula all on iits own set with gobal variavles and it works 100 %

#include<stdio.h>
#include<math.h>
main()
{
float newbalcheq=100, interest =.05, years = 5, oldbalance, INtterest;
INtterest = pow(1+interest/12,12*years);
oldbalance= newbalcheq* INtterest;
printf("%.2f",oldbalance);
getchar();
}
now the thing is when i plug this into my large program it returns 4166

now, this is my main function in which the first if statement is relating to my main menu, it calls the function, then prints the returned value multiplied my the balance( newbalcheq cuz cchequings balance)
main statement
else
if (input == 'c' ||input == 'C')
{
system("cls");
printf("you have selected to add interest");
l= compound (newbalcheq, newbalsave);
newbalance= l*newbalcheq;
printf(" \nyour new balance is %.2f",newbalance);
printf("\nhit enter to return to menu");
fflush(stdin);
getchar();
}
and finaly this is the function compound:
{
printf("you are in chequings");
printf("\nplease enter the amount of months you would like to compound for");
scanf("%f",&years);
printf("\nplease enter your interest rate");
scanf("%f",&interest);
if(newbalcheq>=5000)
{
INtterest = pow(1+interest/12,12*years);
return(INtterest);
fflush(stdin);
getchar();
}

n00bMeiSter
11-26-2010, 05:08 PM
right, I'm saying, scanf("%d", years); because you only want the user to enter a whole number for years. (%d is used to get integer input)

in l= compound (newbalcheq, newbalsave); newbalance= l*newbalcheq; what is l?
and what is it declared as?

it may help to post the entire file, provided it's not ridiculously long.

blackmica10
11-26-2010, 05:19 PM
right, I'm saying, scanf("%d", years); because you only want the user to enter a whole number for years. (%d is used to get integer input)

in l= compound (newbalcheq, newbalsave); newbalance= l*newbalcheq; what is l?
and what is it declared as?

it may help to post the entire file, provided it's not ridiculously long.

ok well its bordereing on 280 lines of code so maybe not lol. i am setting l to take the value returned from the function, which is INtterest inside the function

n00bMeiSter
11-27-2010, 10:16 AM
Aight, tell you what, email me your code and I'll have a look at it.
I've pm'd you my email address.