1. Engineering
  2. Computer Science
  3. c trying to write a program that allows a user...

Question: c trying to write a program that allows a user...

Question details

c++

trying to write a program that allows a user to search an array for a particular number. mines not working please help

#include <iostream>


using namespace std;

int main() {
  
   int array[20];
   int n, k;
   cout << "Enter numbe rof elemtents: ";
   cin >> n;

   cout << "Enter the elemets for the array: ";
   for (int i = 0; i < n; i++) {
       cin >> array[i];
   }
  
   cout << "enter a number to search for in the array" << endl;
   cin >> k;

   for (int i = 0; i < n; i++) {
       if (array[i] == k)
           cout << "the number is in the list";

       else
           cout << "the number does not exist";
   }

   system("pause");
   return 0;
}

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution