Hi,
I have to write a small c++ program that will return the first term (number) of a sequence of positive integers that is less than the immediately preceding term of the sequence.
for example if I enter {6, 5, 7, 8, 9} it will return 5 because it is less than the immediately preceding number. If I enter another array of numbers like {1, 2, 3, 5, 4, 6} it will return 4. and if the array is already in order (that is there is no term less than the immediately preceding term ) it will return the location zero - example {1, 2, 3, 4}, then 0 is returned. I should not use const.
This is my code so far... somewhere something is not correct. please help. I will greatly appreciate it.
GTJ
greggtrent@hotmail.com
I have to write a small c++ program that will return the first term (number) of a sequence of positive integers that is less than the immediately preceding term of the sequence.
for example if I enter {6, 5, 7, 8, 9} it will return 5 because it is less than the immediately preceding number. If I enter another array of numbers like {1, 2, 3, 5, 4, 6} it will return 4. and if the array is already in order (that is there is no term less than the immediately preceding term ) it will return the location zero - example {1, 2, 3, 4}, then 0 is returned. I should not use const.
This is my code so far... somewhere something is not correct. please help. I will greatly appreciate it.
GTJ
greggtrent@hotmail.com
Code:
#include <iostream.h>
void main()
{
int location = 0;
int i = 2;
int n=15;
int *a = new int[n];
cout << "This program will return the first term/number of a sequence of positive integers" << endl;
cout << "that is less than the immediately preceding term of the sequence." << endl << endl ;
cout << "Enter the sequence of integers: ";
cin >> a[n];
a = new int[n];
while (i <= n && location == 0)
{
if (a[i] < (a[i] - 1))
location = i;
else i = i + 1;
}
cout << endl << "The location of the first term is " << a[i] << endl << endl;
}