plz slove this question with array and string

I have the exam with this question, but i cant do it. ill have the re-exam on wednesday someone plz help me !!!!!!!!!


Write a program that accepts a string of 5 digits (0 through 9) and
prints out all possible combinations of these digits which add to 15.
(The digit 0 counts as a 10 in computing the combinations.) For
example, with the input 50154, the output should display the following
(perhaps in some other order):

5 0 1 5 4
- - - - -
5 0
5 1 5 4
0 1 4
0 5

THERE ARE 4 COMBINATIONS TOTALING 15.

Test your program with each of the following inputs: 78787, 55555,
06528.

Sample Run
ENTER A STRING OF 5 DIGITS: 78787

7 8 7 8 7
- - - - -
7 8
8 7
7 8
8 7
7 8

8 7


THERE ARE 6 COMBINATIONS TOTALING 15
No one can do your homework for you, it's against the rules and immoral. Post the code you've attempted and failed at and people will be happy to help you through it. Read the forum rules as well.
^
^
^
^
^
ok Umz
i have do my own but it take like 1000 lines to completed my program i want the short one or the new pattern to write this kind of program. plz anyone gives some comment or ur ideas how to do this



this is how i do it . i know it quite long but unfortunately this is what i can do. but teacher said it's too long. so i want some shorter or an idea to make it shorter. thank you
#include <iostream>
#include <string>

using namespace std;


int main ( void )
{

string digit;
int ASCII [10] = {48,49,50,51,52,53,54,55,56,57};
int a,b,c,d,e,*v,i,z;

cout << "ENTER A STRING OF 5 DIGITS: ";
cin >> digit;

if (digit[0] == ASCII [0]):
a=0;
if (digit[0] == ASCII [1])
a=1;
if (digit[0] == ASCII [2])
a=2;
if (digit[0] == ASCII [3])
a=3;
if (digit[0] == ASCII [4])
a=4;
if (digit[0] == ASCII [5])
a=5;
if (digit[0] == ASCII [6])
a=6;
if (digit[0] == ASCII [7])
a=7;
if (digit[0] == ASCII [8])
a=8;
if (digit[0] == ASCII [9])
a=9;

if (digit[1] == ASCII [0])
b=0;
if (digit[1] == ASCII [1])
b=1;
if (digit[1] == ASCII [2])
b=2;
if (digit[1] == ASCII [3])
b=3;
if (digit[1] == ASCII [4])
b=4;
if (digit[1] == ASCII [5])
b=5;
if (digit[1] == ASCII [6])
b=6;
if (digit[1] == ASCII [7])
b=7;
if (digit[1] == ASCII [8])
b=8;
if (digit[1] == ASCII [9])
b=9;

if (digit[2] == ASCII [0])
c=0;
if (digit[2] == ASCII [1])
c=1;
if (digit[2] == ASCII [2])
c=2;
if (digit[2] == ASCII [3])
c=3;
if (digit[2] == ASCII [4])
c=4;
if (digit[2] == ASCII [5])
c=5;
if (digit[2] == ASCII [6])
c=6;
if (digit[2] == ASCII [7])
c=7;
if (digit[2] == ASCII [8])
c=8;
if (digit[2] == ASCII [9])
c=9;

if (digit[3] == ASCII [0])
d=0;
if (digit[3] == ASCII [1])
d=1;
if (digit[3] == ASCII [2])
d=2;
if (digit[3] == ASCII [3])
d=3;
if (digit[3] == ASCII [4])
d=4;
if (digit[3] == ASCII [5])
d=5;
if (digit[3] == ASCII [6])
d=6;
if (digit[3] == ASCII [7])
d=7;
if (digit[3] == ASCII [8])
d=8;
if (digit[3] == ASCII [9])
d=9;

if (digit[4] == ASCII [0])
e=0;
if (digit[4] == ASCII [1])
e=1;
if (digit[4] == ASCII [2])
e=2;
if (digit[4] == ASCII [3])
e=3;
if (digit[4] == ASCII [4])
e=4;
if (digit[4] == ASCII [5])
e=5;
if (digit[4] == ASCII [6])
e=6;
if (digit[4] == ASCII [7])
e=7;
if (digit[4] == ASCII [8])
e=8;
if (digit[4] == ASCII [9])
digit[4]=9;

cout <<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<'\n';
for (i=0;i<5;i++){
cout <<"-"<<" ";}



if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=10;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=10;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=10;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=10;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=10;
}
cout << '\n';








if (a + b == 15)
{
if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=0;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=0;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=0;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=0;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=0;
}
cout<<a<<" "<<b<<'\n';
z=1;
}

if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=10;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=10;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=10;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=10;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=10;
}






if (a + c == 15)
{
if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=0;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=0;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=0;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=0;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=0;
}
cout<<a<<" "<<" "<<" "<<c<<'\n';
z=1;
}


if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=10;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=10;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=10;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=10;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=10;
}




if (a + d == 15)
{
if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=0;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=0;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=0;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=0;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=0;
}
cout<<a<<" "<<" "<<" "<<" "<<" "<<d<<'\n';
z=1;
}


if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=10;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=10;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=10;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=10;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=10;
}




if (a + e == 15)
{
if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=0;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=0;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=0;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=0;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=0;
}
cout<<a<<" "<<" "<<" "<<" "<<" "<<" "<<" "<<e<<'\n';
z=1;
}


if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=10;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=10;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=10;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=10;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=10;
}





if (a + b + c == 15)
{
if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=0;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=0;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=0;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=0;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=0;
}
cout<<a<<" "<<b<<" "<<c<<'\n';
z=1;
}


if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=10;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=10;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=10;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=10;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=10;
}




if (a + b + d == 15)
{
if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=0;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=0;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=0;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=0;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=0;
}
cout<<a<<" "<<b<<" "<<" "<<" "<<d<<'\n';
z=1;
}



if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=10;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=10;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=10;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=10;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=10;
}



if (a + b + e == 15)
{
if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=0;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=0;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=0;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=0;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=0;
}
cout<<a<<" "<<b<<" "<<" "<<" "<<" "<<" "<<e<<'\n';
z=1;
}

if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=10;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=10;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=10;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=10;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=10;
}



if (a + c + d == 15)
{
if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=0;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=0;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=0;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=0;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=0;
}
cout<<a<<" "<<" "<<" "<<c<<" "<<d<<'\n';
z=1;
}

if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=10;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=10;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=10;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=10;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=10;
}





if (a + c + e == 15)
{
if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=0;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=0;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=0;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=0;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=0;
}
cout<<a<<" "<<" "<<" "<<c<<" "<<" "<<" "<<e<<'\n';
z=1;
}


if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=10;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=10;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=10;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=10;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=10;
}




if (a + d + e == 15)
{
if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=0;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=0;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=0;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=0;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=0;
}
cout<<a<<" "<<" "<<" "<<d<<" "<<e<<'\n';
z=1;
}

if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=10;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=10;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=10;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=10;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=10;
}





if (a + b + c + d == 15)
{
if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=0;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=0;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=0;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=0;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=0;
}
cout<<a<<" "<<b<<" "<<c<<" "<<d<<'\n';
z=1;
}

if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=10;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=10;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=10;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=10;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=10;
}




if (a + b + c + e == 15)
{
if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=0;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=0;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=0;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=0;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=0;
}
cout<<a<<" "<<b<<" "<<c<<" "<<" "<<" "<<e<<'\n';
z=1;
}
if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=10;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=10;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=10;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=10;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=10;
}





if (a + b + d + e == 15)
{
if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=0;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=0;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=0;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=0;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=0;
}
cout<<a<<" "<<b<<" "<<" "<<" "<<d<<" "<<e<<'\n';
z=1;
}

if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=10;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=10;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=10;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=10;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=10;
}


if (a + c + d + e == 15)
{
if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=0;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=0;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=0;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=0;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=0;
}
cout<<a<<" "<<" "<<" "<<c<<" "<<d<<" "<<e<<'\n';
z=1;
}

if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=10;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=10;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=10;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=10;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=10;
}


if (b + c == 15)
{
if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=0;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=0;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=0;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=0;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=0;
}
cout<<" "<<" "<<b<<" "<<c<<'\n';
z=1;
}


if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=10;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=10;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=10;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=10;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=10;
}
if (b + d == 15)
{
if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=0;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=0;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=0;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=0;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=0;
}
cout<<" "<<" "<<b<<" "<<" "<<" "<<d<<'\n';
z=1;
}


if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=10;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=10;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=10;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=10;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=10;
}




if (b + e == 15)
{
if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=0;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=0;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=0;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=0;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=0;
}
cout<<" "<<" "<<b<<" "<<" "<<" "<<" "<<" "<<e<<'\n';
z=1;
}


if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=10;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=10;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=10;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=10;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=10;
}


if (b + c + d == 15)
{
if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=0;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=0;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=0;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=0;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=0;
}
cout<<" "<<" "<<b<<" "<<c<<" "<<d<<'\n';
z=1;
}

if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=10;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=10;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=10;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=10;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=10;
}




if (b + c + e == 15)
{
if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=0;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=0;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=0;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=0;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=0;
}
cout<<" "<<" "<<b<<" "<<c<<" "<<" "<<" "<<e<<'\n';
z=1;
}

if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=10;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=10;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=10;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=10;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=10;
}





if (b + d + e == 15)
{
if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=0;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=0;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=0;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=0;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=0;
}
cout<<" "<<" "<<b<<" "<<" "<<" "<<d<<" "<<e<<'\n';
z=1;
}


if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=10;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=10;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=10;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=10;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=10;
}





if (b + c + d + e == 15)
{
if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=0;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=0;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=0;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=0;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=0;
}
cout<<" "<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<'\n';
z=1;
}


if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=10;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=10;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=10;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=10;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=10;
}





if (c + d == 15)
{
if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=0;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=0;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=0;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=0;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=0;
}
cout<<" "<<" "<<" "<<" "<<c<<" "<<d<<'\n';
z=1;
}
if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=10;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=10;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=10;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=10;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=10;
}





if (c + e == 15)
{
if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=0;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=0;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=0;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=0;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=0;
}
cout<<" "<<" "<<" "<<" "<<c<<" "<<" "<<" "<<e<<'\n';
z=1;
}

if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=10;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=10;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=10;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=10;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=10;
}




if (c + d + e == 15)
{
if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=0;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=0;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=0;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=0;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=0;
}
cout<<" "<<" "<<" "<<" "<<c<<" "<<d<<" "<<e<<'\n';
z=1;
}
if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=10;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=10;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=10;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=10;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=10;
}



if (d + e == 15)
{
if (digit[0] == ASCII [0])
{
v=&a;
*(int*)v=0;
}
if (digit[1] == ASCII [0])
{
v=&b;
*(int*)v=0;
}
if( digit[2] == ASCII [0])
{
v=&c;
*(int*)v=0;
}
if (digit[3] == ASCII [0])
{
v=&d;
*(int*)v=0;
}
if (digit[4] == ASCII [0])
{
v=&e;
*(int*)v=0;
}
cout<<" "<<" "<<" "<<" "<<" "<<" "<<d<<" "<<e<<'\n';
z=1;
}
'/n'; system("pause");

}
this is how i did,,i knw it's too long but i have jst learn and this is all i can do ,, plz help :)
When you post code, put it into code tags using that angle-brackets button.
And there has to be a better way than brute force. No way I'm going to read all of that, but it sounds like a combinatorics problem to me.
Do you have to use a string or can you use an array of integers?
If you use an array (entirely conjecture here but my logic suggests this), then you can loop through the array for each number and, in a series of nested loops, perform various additions to examine the potential combinations.

EDIT: And Umz is right, nobody can or should just give you a solution. What we can do is point you to the right logic and give you some suggestions on the code you should use.
Last edited on
You need to work with loops more.

You're copy/pasting a lot of code and just changing the index each time. If you use a loop instead, you can write the code once and use a variable for the index.

For example... you're doing this:

1
2
3
4
5
6
7
8
9
10
11
if (digit[0] == ASCII [0])
  a=0;
if (digit[0] == ASCII [1])
  a=1;
if (digit[0] == ASCII [2])
  a=2;
if (digit[0] == ASCII [3])
  a=3;
//...
if (digit[0] == ASCII [9])
  a=9;


If you use a loop, you can shorten it dramatically:

1
2
3
4
5
6
int i;  // your loop counter
for(i = 0; i < 10; ++i)
{
  if(digit[0] == ASCII[ i ])  // notice here we use 'i' to index ASCII
    a = i;                           // and here to set 'a'
}


The idea is that each time the loop runs, 'i' will increment, meaning it'll be 0 the first time, then 1, then 2, etc, etc. So in effect, this little bit of code does the same thing as your code above.


Also note that you can take this even further. Instead of making a, b, c, d, and e different variables, you can make them an array so that you can index them instead of having to reference each variable directly:

1
2
3
4
5
// int a, b, c, d, e;  // bad
int nums[5];  // better

// a = 0;  // bad
nums[0] = 0;  // better because now we have an index. 


An index isn't always better... but in this case it's nice because it means we can put this in another loop. Instead of copy/pasting code for a, b, c, etc... you can put all of that code in another loop (like the above) and use the same code for each var.


But even all of this isn't ideal. Take a look at what you're actually doing here:

1
2
3
4
5
6
7
if (digit[0] == ASCII [0])  // note:  ASCII[0] == 48
  a=0;
if (digit[0] == ASCII [1])  // note:  ASCII[1] == 49
  a=1;
if (digit[0] == ASCII [1])  // note:  ASCII[2] == 50
  a=1;
// etc 


Basically you're converting the following:


48 -> 0
49 -> 1
50 -> 2
51 -> 3
52 -> 4
etc


Do you really need if for that? You should see a very simple pattern there. You don't need an 'if' statement at all for this.
Wow. Sir I must commend you on your patience to copy and paste so much code.

Disch broke the problem up perfectly. Look into using loops instead of the if's
Topic archived. No new replies allowed.