Input Value(arrays)

Guys,
I am stuck where it says if user want to put wrong order then program should not accept it. I don't know how to put that in code-

Pls Help

------------------------------------------
Suppose A, B, C are arrays of integers of size M, N, and M + N respectively. The numbers in array A appear in ascending order while the numbers in array B appear in descending order.
Write a user defined function in C++ to produce third array C by merging arrays A and B in ascending order. Use A, B and C as arguments in the function. You will need to ask user to input M and N, and based on those inputs user needs to fill the arrays A and B in an appropriate order. If user wants to input wrong order of values, your program should not accept it, and should ask for appropriate value.


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
#include<iostream>
using namespace std;
void merge(int A[], int B[], int C[], int m, int n, int &k);

int main(){
	int A[100], B[100], C[100], n, m, k;
	//int num1=0;
	
	cout << " Enter number of element to enter in array 1: " << endl;
	cin >> n;
	cout << " Enter element in ascending order, "; 
	for (int i = 0; i < n; i++){
		cout << "Enter a number " << i + 1 << ": ";
		cin >> A[i];


		//compare first to second input, and second to third
	}

		cout << "Enter number of element to enter in array 2: " << endl;
		cin >> m;
		cout << "Enter numbers in descending order, ";
		for (int i = 0; i < m; i++)
		{
			cout << "Enter a number " << i + 1 << " :";
			cin >> B[i];
// Compare first to second and second to third and so on 
		}


		merge(A, B, C, n, m, k);
		cout << " The Merging array in Ascending order: " << endl;
		for (int i = 0; i < k; i++){
			cout << C[i] << " ";
		}
		return 0;

	}
}
void merge(int A[], int B[], int C[], int m, int n, int &k){
	I know what to do here -
}
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
#include <iostream>
#include <vector> // http://www.mochima.com/tutorials/vectors.html

int main()
{
    std::cout << " Enter number of elements in array 1: " ;
    std::size_t n ;
    std::cin >> n;

    std::vector<int> A ;

    if( n > 0 )
    {
        std::cout << " Enter elements in ascending order: " ;

        int number ;

        // enter the first number
        std::cout << "Enter a number: " ;
        std::cin >> number ;

        // enter remaining numbers
        while( A.size() < n )
        {
            std::cout << "Enter a number: " ;
            std::cin >> number ;

            // check if the number entered is greater than than the last one so far
            if( number <= A.back() ) // change <= to < for non-descending order
                std::cout << "Please enter a number greater than " << A.back() << '\n' ;
            else A.push_back(n) ;
        }
    }
}
Topic archived. No new replies allowed.