please help with 1d array 1-9

Write a program that looks at a 1D array of 9 numbers and verifies that the array contains each of the
numbers 1-9 exactly once.
It should display a message "Valid Array!" if the array meets the requirement.
Otherwise, your program should let the user know what is wrong with the array.
(Does it contain a number out of the range? Is a number not found in the array? Is a number duplicated?)

#include <iostream>

using namespace std;

int main ()

int number;
int array[8] {1,2,3,4,5,6,7,8,9} ;
{

cout<<"Enter a number in the range 1-9:\n";
cin>>number
while (number < 1 || number > 9)



return 0;
with here.
[/code]
closed account (48T7M4Gy)
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
#include <iostream>

using namespace std;

int main ()
{
    int number = 0;
    int array[10]{};
    
    while
        (
         cout << "Enter a number in the range 1-9 ( -1 to end ): " &&
         cin >> number &&
         number != -1
         )
    {
        if(number > 0 && number < 10)
            array[number]++;
        else
            cout << number << " wrong!\n";
        
    }
    
    for(int i = 1; i < 10; ++i)
        cout << i << " occurred " << array[i] << " times.\n";
    
    return 0;
}
Topic archived. No new replies allowed.