School assignement (Addition in all possibilites)

Hello,

I have an assignement and I cant figure it out how to do it. In my head I only get infinite loops...

Assignement :
User inputs number m and I need to use numbers 10, 15, 25. So my program needs to do the addition in all possibilites with numbers that I can use to get number m and has to write it down.

----------------------
Example :
User inputs m=25
Output :
0 0 1
1 1 0
----------------------

These three numbers represents 10, 15, 25.

Thanks for any help. If I complete this assignement (Its not hard, but I am missing something) my Life is going to be much Easier.
Last edited on
In my head I only get infinite loops... That's one hilarious comment. How about stop doing the assignment in your head, but instead do it with code?

If I complete this assignement (Its not hard, but I am missing something)


Missing something? Are you saying you are almost done but there is one missing piece? Be specific.

Also, is there a reason you posted this in the Window programming section, it doesnt seem to have anything to do with windows.
Last edited on
Hello TarikNeaj, thanks for reply,

I am not missing a piece I just don't know how to do it :P
In this program I think I only need some for loops, I know the code for this assignements are simple maybe 20-25 lines of code, If I do it my way I will finish it with 100+ Lines of code.

Coding is not problem, I am not a newbie, I just don't know how to do programs like this one. Whatever I start writing or thinking I get this: "it will do for this but not for that."
If I do it my way I will finish it with 100+ Lines of code.


That's okay. Make it 100 lines of code. After it's working you can start to improve it. You can ask specific questions about how to improve certain parts.
Ok, I'll do it my way, I will reply to this topic again if I need help so stay tune.

Thanks for advice and Helping me always @TarikNeaj !
My Variables :
----
f - First number (10)
s - Second number (15)
t - Third number (25)
sum - sum of numbers in for loops until I get : sum==m;
----

I've come this far, I get duplicated results, Btw. its not always right eg. m=30
output is :
3 0 0
3 0 0
3 0 0
should be :
3 0 0
0 2 0

Code :
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include <iostream>

using namespace std;

int main() {

	int m = 0; int sum = 0; int f = 0; int s = 0; int t = 0; int num = 0;

	cin >> m;

	if (m < 10) {
		cout << "Addition is not possible";
	}
	else {
		
				
			
				for (int i = 0; i < 4; i++) {
					sum = 0;
					f = 0;
					s = 0;		
					t = 0;
					if (i == 0) {
						sum += 10;
						f++;
						num = 10;
					}
					else if (i == 1) {
						sum += 15;
						s++;
						num = 15;
					}
					else if (i == 2) {
						sum += 25;
						t++;
						num = 25;
					}
					else if (i == 3) {
						sum += 0;
						num = 0;
					}
					if (sum == m) {
						cout << f << " " << s << " " << t << endl;
						sum = sum - num;
						if (num == 10) { f--; }
						if (num == 15) { s--; }
						if (num == 25) { t--; }
					
					}
					else if (sum > m) {
						sum = sum - num;
						if (num == 10) { f--; }
						if (num == 15) { s--; }
						if (num == 25) { t--; }
					}
					for (int j = 0; j < 4; j++) {
						if (j == 0) {
							sum += 10;
							f++;
							num = 10;
						}
						else if (j == 1) {
							sum += 15;
							s++;
							num = 15;
						}
						else if (j == 2) {
							sum += 25;
							t++;
							num = 25;
						}
						else if (j == 3) {
							sum += 0;
							num = 0;
						}
						if (sum == m) {
							cout << f << " " << s << " " << t << endl;
							sum = sum - num;
							if (num == 10) { f--; }
							if (num == 15) { s--; }
							if (num == 25) { t--; }
						}
						else if (sum > m) {
							sum = sum - num;
							if (num == 10) { f--; }
							if (num == 15) { s--; }
							if (num == 25) { t--; }
						}
						for (int k = 0; k < 4; k++) {
							if (k == 0) {
								sum += 10;
								f++;
								num = 10;
							}
							else if (k == 1) {
								sum += 15;
								s++;
								num = 15;
							}
							else if (k == 2) {
								sum += 25;
								t++;
								num = 25;
							}
							else if (k == 3) {
								sum += 0;
								num = 0;
							}
							if (sum == m) {
								cout << f << " " << s << " " << t << endl;
								sum = sum-num;
								if (num == 10) { f--; }
								if (num == 15) { s--; }
								if (num == 25) { t--; }
							}
							else if (sum > m) {
								sum = sum - num;
								if (num == 10) { f--; }
								if (num == 15) { s--; }
								if (num == 25) { t--; }
							}
						}
					
					}
				
					
					
				}
		
	}

	system("pause");
	return 0;
}


Last edited on
Topic archived. No new replies allowed.