Windows has encountered a problem

Could you help me understand why i get a don't send error with no warnings and no errors?

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
#include<iostream>
using namespace std;
int main ()
{
	int v[50];
	int m,a,x,g,i,b,s;
	long int n;
	cout<<"enter the value of n"<< endl;
	cin>>n;
	g=n;
	if (n>=1)
	{
		while (n!=0)
		{	
			a=n%10;
			if (a%2!=0)
			{	v[i]=a;
				m++;
			}
		n=n/10;
	}
		if (m==0)
		cout<<"0";
		do
		{
			s=0;
			for (i=0;i<=m;i++)
			{
				if (v[i]<v[i+1])
					{	b=v[i];
					v[i]=v[i+1];
					v[i+1]=b;
					s=1;
				}
			}
		}
		while (s==0);
		for (i=0;i<=n;i++)
			x=x*10+v[i];
		if (x==g)
			cout<<"no";
		else 
			cout<<x-g;
		}
}
What do you expect to do with this code snippet?
I mean your variables are not really descriptive you know!

And what problem do you encounter?
I haven't the slightest incline what that is supposed to do. The first thing that came to mind is you're violating the bounds of v.

Wazzak
Last edited on
it was supposed to analyze a number, extract the odd numbers, count how many there are, rearrange the number and decrease the first number from the second, reaarranged one.

and the problem is a don't send message, the snippet just won't run
based on your indenting I'd say that the problem is at line 21. This bracket ends the while loop, not the if statement.
Okay, I've read a little more and I see twothree things:
1: You never initialize x used on line 39.
2: In line 38 you use i<=n. if n is 50, then you go out of bounds.
3: You don't initialize i before use in line 17. This means that is is almost guaranteed to be above 50 and you're going out of bounds.
Last edited on
thank you for the feedback, i'm really noob at this and a fresh eye is always helpfull
Topic archived. No new replies allowed.