Hi.
I have a problem with the bool increasing funtction.
It seems it only compares the first 2 numbers in any situation.
Example input;
10 for int n, then enter 10 numbers
3704 7061 3245 111 4376 8101 1188 9051 818 1187
I should get not increasing from this but I get increasing.
Lets look at your function. Iteration starts. i==0.
IF arr[1] > arr[0]
THEN end function and return true
ELSE end function and return false.
The second if-clause is never evaluated. The loop never proceeds any further.
Conclusion: you cannot return from within the loop since you need to check that every pair is increasing. You can return early for a "fail case" though.
As it is the program runs forever as the while loop waits for cin input from the user.
Do you want the user to enter the numbers? If so you need to begin with something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
usingnamespace std;
int main() {
int arr[5];
int n = 0;
cout << "Enter 5 numbers: " << endl;
while(n<5)
{
cin >> arr[n];
n++;
}
return 0;
}
Also the if else statements in your increasing() function need changing, the second if else is unnecessary and will never be be used as the function will always return from the first if else block (unless the arr[i+1] == arr[i])
As it is the program runs forever as the while loop waits for cin input from the user.
That is not a problem.
Yes, the program asks for a number and if it gets one, then it takes as many values and tells something about them. This repeats as many times as the user wants. Giving a non-number or EOF ends the loop. Perfectly fine.
At line 26, you're looping for 99 times, even though the user may have entered N as less than 100. This means you're comparing uninitialized array locations.
As it is the program runs forever as the while loop waits for cin input from the user.
That is not a problem.
Yes, the program asks for a number and if it gets one, then it takes as many values and tells something about them. This repeats as many times as the user wants. Giving a non-number or EOF ends the loop. Perfectly fine.
My output where we return our program in mooshak returns this.
Output was not correct
Difference between obtained and expected output
Obtained output
Expected output
n 1 not increasing n
2 not increasing 1 not increasing
3 not increasing 2 not increasing
4 not increasing 3 not increasing
5 increasing 4 increasing
6 increasing 5 increasing
t t 6 increasing