need some tips to finish :)

Write your question here.
Hi, im just new here :) i think im finish with my project but somethings wrong
with the computation part,at first it computes the 1st set of number row but after that it just copies the number i dont know why it does not subtract anymore :)) i just need some tips to why its not working ty :)
here is my code

edit: now i know the problem clearer, i want to ask for some hints on what will i use to store the value of the subtracted results :)


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
#include <iostream>
#include <stdlib.h>

using namespace std;

int input[10];
int dif[10];

int dami;
int space;

int i;
int j;

int main()
{
	cout << "How many numbers you will enter, maximum of 10:\n";
	cin >> dami;
	if (dami > 10)
	{
		cout << "Number exceeds limit try again\n";
		system("pause");
		system("CLS");
		main();
	}
	else
	{
		cout << "Enter " << dami << " numbers not greater than 100000 and not lower than 0:\n";
		for (i = 0; i <dami; i++)
		{
			cin >> input[i];

			if (input[i] > 100000)
			{
				cout << "\nInput is too large";
				system("pause");
				system("CLS");
				main();
			}
		}

		cout << "\n";
		for (int z = 0; z < dami; z++)
		{
			cout << input[z] << "  ";	
		}
		/*for (space = 0; space < dami - i; ++space)
		{

			cout << "";
		}*/
		cout << "\n";
		for (i = 0; i < dami; i++)
		{
			
			for (j = i; j < dami - 1; j++)
			{
				dif[j] = input[j + 1] - input[j];
				cout << "  " << dif[j];	
			}
			cout << "\n";		
		}
	}
	cout << "\n";
	system("pause");
}
Last edited on
Do not call main(). You could use loops instead.
uhm i dont have problem with the main part :)

here is the problem for example i input 1 5 11 26 its output shows

1 5 11 26
 4  6  15
   6  15
    15
it should be

1 5 11 26
  4  6  15
    2  9
      7
some hints would be a big help :)
That is due to lines 58-59. You calculate differences from the original input every time.

You could, for example, replace the input with differences. That way each iteration would start with new input.
uhm i dont have problem with the main part :)

Regardless of whether you have a problem with it or not, it is not standard C++ therefore - don't do it. Use a loop instead.

The standard says in ยง3.6.1.3:

The function main shall not be used within a program.
I see, thank you for your replies :)
Topic archived. No new replies allowed.