#include<stdio.h>
#include<conio.h>
main(){
int p,v,n;
double r;
for(p=1000;p<=10000;p=p+1000)
for(r=0.10;r<=0.20;r=r+0.01)
for(n=1;n<=10;n++){
v=p*1+r;
p=v;
printf("Value of money %d",v);
printf("Principal %d",p);
printf("time %d",n);
printf("Rates %d",r);
}
getch();
return 0;
}
Basic C program what am I doing wrong?
- the outmost for-loop will only run once
- if p is an int, you cannot just call it as a function: 'v=p(1+r);'
You really should be using [ code ]-tags, it's pretty much unreadable like that. Couple of thoughts:
Apart from that it would help to describe the actual problem. Does it compile (probably not)? Does it produce the wrong values? What do you expect at all? What do you get instead?
- the outmost for-loop will only run once
- if p is an int, you cannot just call it as a function: 'v=p(1+r);'
Ohh that was a typo mate and still thanks for the help.
But the main problem is not that it is compiling and running...But I am not getting the result I want.
p=v;
printf("Value of money %d",v);
printf("Principal %d",p);
If you set p = v, and then print out v and p, you're just printing out the same value twice.
Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.
You don't forget how to play when you grow old; you grow old when you forget how to play.
for(p=1000;p<=1000;p=p+10000)
This will never enter the loop
That was a typo too....I did that mistake when typing in the forum but the main problem is
I want to get the value of money when the principal is 1000 and the rate it 0.10 and time is 1 and then principal 2000 rate is 0.11 and then time 2.
But that program is finding all the possible combination of those and idk how to restrict
p=v;
printf("Value of money %d",v);
printf("Principal %d",p);
If you set p = v, and then print out v and p, you're just printing out the same value twice.
Yes lol
Thanks!
Okay thanks brothers I solved it
#include<stdio.h>
#include<math.h>
#include<conio.h>
void main()
{
int i,n,p,j;
double v,r,t;
printf("\n\n\n");
clrscr();
r=0.10;
n=10;
p=1000;
t=pow((1+r),i);
// printf("\n\n%.6lf ",t);
printf("\nP R N V\n");
for(i=1;i<=n;i++)
{
if(r<=0.20 && p<=10000)
{
t=pow((1+r),i);
v=p*t;
p=p+1000;
r=r+0.01;
}
printf("%d %lf %d ",p,r,n);
printf("V=% .6lf ",v);
printf("\n");
}
getch();
}
Well I am a noob...No need to mention though
v = p*1+r doesn't give you what you think it does. If you want to multiply p by 1 + r, then you need some parentheses: v = p * (1 + r)
BTW, I hope this isn't a homework assignment...
Prepare to have your hopes dashed Dave Hunt... I doubt he's working on the next gen interest calculator game.
- Eck
EckTech Games - Games and Unity Assets I'm working on
Still Flying - My GameDev journal
The Shilwulf Dynasty - Campaign notes for my Rogue Trader RPG