Problem i can't find

my program doesn't work can anyone help me what's my the problem



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
#include<iostream>
using namespace std;

class Cnumbers{
public:
	Cnumbers();
	void input();
	void miavorel();
	void output();
private:
	int a[3];
	int b[3];
	int c[6];
};

int main()
{
	Cnumbers num;
	num.input();
	num.miavorel();
	num.output();
	return 0;
}
Cnumbers::Cnumbers()
{
	for(int i=1;i<=6;i++)
		a[i]=0;
	for(int j=1;j<=3;j++)
		b[j]=0;
}
void Cnumbers::input()
{
	for(int i=1;i<=3;i++)
		cin>>a[i];
	for(int j=1;j<=3;j++)
		cin>>b[j];
	
}
void Cnumbers::miavorel()
{
	for(int i=1;i<=3;i++)
	{
		for(int j=1;j<=3;j++)
			if(a[i]!=b[j])
			{
				for(int k=1;k<=6;k++)
					c[k]=a[i];c[k+1]=b[j];
			}
				else 
					for(int k=1;k<=6;k++)
					c[k]=a[i];
	}
}
void Cnumbers::output()
{
	for(int i=1;i<=6;i++)
		cout<<c[i]<<endl;
}



Last edited on
closed account (S6k9GNh0)
What doesn't work about it. Could we get the error it gave you.
There is no errors but when i run my program windows give me a problem
When talking to programmers, try using more specific phrases than "doesn't work" and "a problem".

Without looking too hard, and based on your indentation, I can tell that the for that starts on line 43 needs braces, and so does the one that starts on line 46.
closed account (z05DSL3A)
Just a few things you may have problems with:

Index '6' is out of valid index range '0' to '2' for possibly stack allocated buffer 'a' 27
Index '3' is out of valid index range '0' to '2' for possibly stack allocated buffer 'b' 29
Buffer overrun: accessing 'a', the writable size is '12' bytes, but '16' bytes might be written: Lines: 26, 27
Buffer overrun: accessing 'b', the writable size is '12' bytes, but '16' bytes might be written: Lines: 26, 27, 26, 27, 26, 27, 26, 28, 29
Index '3' is out of valid index range '0' to '2' for possibly stack allocated buffer 'a' 34
Index '3' is out of valid index range '0' to '2' for possibly stack allocated buffer 'b' 36
Invalid data: accessing 'a', the readable size is '12' bytes, but '16' bytes might be read: Lines: 33, 34
Invalid data: accessing 'b', the readable size is '12' bytes, but '16' bytes might be read: Lines: 33, 34, 33, 34, 33, 34, 33, 35, 36
Index '3' is out of valid index range '0' to '2' for possibly stack allocated buffer 'a' 45
Index '3' is out of valid index range '0' to '2' for possibly stack allocated buffer 'b' 45
Index '6' is out of valid index range '0' to '5' for possibly stack allocated buffer 'c' 49
Index '3' is out of valid index range '0' to '2' for possibly stack allocated buffer 'a' 49
Index '3' is out of valid index range '0' to '2' for possibly stack allocated buffer 'b' 49
Index '6' is out of valid index range '0' to '5' for possibly stack allocated buffer 'c' 56
Index '3' is out of valid index range '0' to '2' for possibly stack allocated buffer 'a' 56
Invalid data: accessing 'b', the readable size is '12' bytes, but '16' bytes might be read: Lines: 41, 43, 45
Index '6' is out of valid index range '0' to '5' for possibly stack allocated buffer 'c' 65

Based on the reformatted 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
#include<iostream>
using namespace std;

class Cnumbers{
public:
    Cnumbers();
    void input();
    void miavorel();
    void output();
private:
    int a[3];
    int b[3];
    int c[6];
};

int main()
{
    Cnumbers num;
    num.input();
    num.miavorel();
    num.output();
    return 0;
}
Cnumbers::Cnumbers()
{
    for(int i=1;i<=6;i++) 
        a[i]=0;
    for(int j=1;j<=3;j++)
        b[j]=0;
}
void Cnumbers::input()
{
    for(int i=1;i<=3;i++)
        cin>>a[i];
    for(int j=1;j<=3;j++)
        cin>>b[j];
    
}
void Cnumbers::miavorel()
{
    for(int i=1;i<=3;i++)
    {
        for(int j=1;j<=3;j++)
        {
            if(a[i]!=b[j])
            {
                for(int k=1;k<=6;k++)
                {
                    c[k]=a[i];c[k+1]=b[j];
                }
            }
            else
            {
                for(int k=1;k<=6;k++)
                {
                    c[k]=a[i];
                }
            }
        }
    }
}
void Cnumbers::output()
{
    for(int i=1;i<=6;i++)
        cout<<c[i]<<endl;
}

Last edited on
Grey Wolf when i want to run this reformatted code that doesn 't run wholly!
closed account (z05DSL3A)
The code does not fix your indexing problems...

for example:
1
2
    for(int i=1;i<=6;i++) 
        a[i]=0;


a[0] is not initialized, and when i is 3 and above you are writing outside of the bounds of a[].
Topic archived. No new replies allowed.