simplify functions

Pages: 12
How about you go ask your tutor and not 'us guys', we don't take orders. We are here to help people. But we don't do peoples assignments for them.
I believe you'll find the following useful:

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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <iostream>
using namespace std;

void print_multiples_of4(int x, int y);
int odd_count(int x, int y); 
void swap(int x, int y);

int main()
{
	int x;
	int y;

	cout << "enter x y:";
	cin >> x >> y;

	cout << "calling print_multiples_of4(" << x << ',' << y << ")...";
	print_multiples_of4(x,y);

	cout << "\n\nenter x y:";
	cin >> x >> y;

	cout << "odd_count(" << x << ',' << y << ")=";
	cout << odd_count(x,y);

	cout << "\n\nenter x y:";
	cin >> x >> y;

	cout << "(x,y) before swap -> (" << x << ',' << y << ')';
	swap(x,y);
	cout << "\n(x,y) after swap -> (" << x << ',' << y << ')';

	cin.get();
	return 0;		
}


void print_multiples_of4(int x, int y)
{

	//here you'll have to use a for loop
	//with the loop variable iterating
	//from x to y

	//to check if a number is a multiple of 4
	//(i.e. it is divisible by 4)
	//use the % operator, somehow...

	return;
}

int odd_count(int x, int y)
{
	int count;

	//again use a for loop
	//with the loop var iterating
	//from x to y

	//to check if a number is odd
	//check if it is a multiple of 2 ;)

        return count;
}

void swap(int x, int y)
{
	//I'll give you this one
	//because I feel generous today

	x=y;
	y=x;

	//But I'm not really sure it works...
	//I haven't tested it myself.
	//Perhaps you'll have to make
	//slight modifications in the way you
	//pass the arguments and even
	//in the algorithm itself...

        return;
}

Info on loops -> http://cplusplus.com/doc/tutorial/control/
Info on % operator -> http://cplusplus.com/doc/tutorial/operators/
Info on ways of argument passing -> http://cplusplus.com/doc/tutorial/functions2/
Last edited on
Ah that was nice of you m4ster r0shi, thats what I was hoping he would do. Time to see if he can make some use of that then :)
ok that was really generous of u ... o i really appreciate it

and mythios .. i didnt mean to give orders

but im reallu in need and i had no idea how to do it .. so im sorry
Topic archived. No new replies allowed.
Pages: 12