Help fixing my Program?

somehow the pow funkiton wont work propperly... the prints are in german just fyi =D


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include <math.h>

int main()

{
	int n = 0;
	int K = 0;
	int p = 0.03;
	double Kn1 = 0;
	double Kn2 = 0;
	double x = 0;
	double y = 0;
	
		
	printf("		Zinsprogramm		\n");
	printf("		------------		\n\n");
	printf("	Bitte Laufzeit in Jahren eingeben:\n"); //insert runtime in years

	scanf("%d", &n);

	printf("	Bitte Kapital eingeben:\n\n"); //insert your capital

	scanf("%d", &K);

	printf("	Der Zins betraegt 3%%.\n"); //interest rate is 3%

	Kn1 = K*(1+p);

	x = Kn1;
	y = n;

	Kn2 = pow( x, y );


	printf("	Nach %d Jahren ist ihr Kapital auf %lf gestiegen",n ,Kn2);
//after x years your capital has risen to y
	printf("\n");
	printf("\n");
	printf("\n");
	printf("\n");

	return 0;
}
Last edited on
What do you mean by not working? Is it returning the wrong value?
int p = 0.03;

What kind of integer is this? The kind with decimal places? That's not an integer.
@OP if you want to do something like p=0.03, make p a float
@Peter87 The "not working" part is, it outputs 3200000000000000000000 instead of 23000

@Moschops int p = 0.03; wasnt supposed to be an int, it was a double before but i tried some things and thought they might fix it and forgot to change that one back.

@Aceix I pretty much started with C about 2 weeks ago in school but my teacher is to lazy or doesn't know how to make this work. Does making it a float require me to change anything else except for that and the placeholders?
Last edited on
I think you should use %f instead of %lf.
would that really make a difference?
I think so. %f is for float and double, and %lf is for long double if I'm not mistaken.
@Moschops changing it didnt make a difference

@Peter87 didnt change anything

in other news, i commented the text with translation ^^
Now that you have changed the code, you must show us the code if you want us to be able to tell you what the next mistake is.
Topic archived. No new replies allowed.