Mar 10, 2014 at 9:40am UTC
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 Mar 10, 2014 at 10:13am UTC
Mar 10, 2014 at 9:44am UTC
Do not call main() . You could use loops instead.
Mar 10, 2014 at 12:03pm UTC
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.
Mar 10, 2014 at 3:27pm UTC
I see, thank you for your replies :)