adding a variable percentage

need to change program so that I can add a variable percentage of the double x to x_accum

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
#include<stdio.h>
#include<iostream>
void sum(int, int, int *p);
int main()
{
	int x;
	int y;
	int accum;
	int *p;
	p = &accum;
	
	x=5;
	y=4;
	accum =5;
	sum(x, y, p);
	printf("%d\n", accum);

	return 0;
}
void sum(int x, int y, int*p)
{
	if(x<y)
		*p+=x;
	else
		*p+=y;
}
Basic user input. If that's not what you want, clarify the question.
By the way, you could pass
sum(x,y,&accum);
and it would still work. Or you could do it the easy way and change the argument p to reference.
Topic archived. No new replies allowed.