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.
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.
#include <iostream>
usingnamespace 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;
}
elseif (i == 1) {
sum += 15;
s++;
num = 15;
}
elseif (i == 2) {
sum += 25;
t++;
num = 25;
}
elseif (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--; }
}
elseif (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;
}
elseif (j == 1) {
sum += 15;
s++;
num = 15;
}
elseif (j == 2) {
sum += 25;
t++;
num = 25;
}
elseif (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--; }
}
elseif (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;
}
elseif (k == 1) {
sum += 15;
s++;
num = 15;
}
elseif (k == 2) {
sum += 25;
t++;
num = 25;
}
elseif (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--; }
}
elseif (sum > m) {
sum = sum - num;
if (num == 10) { f--; }
if (num == 15) { s--; }
if (num == 25) { t--; }
}
}
}
}
}
system("pause");
return 0;
}