Good Afternoon,
I'm having trouble with an assignments that deals with arrays. I'm stuck in the part that says Decide whether the value entered by the user at (2) is in the array numbers[SIZE] or not.
So far I have this code
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iomanip>
using namespace std;
int main( )
{
//define a const array size
const int SIZE = 10;
//array declaration
int cat[5]; //declare an array without initialization
int dog[5]={11, 22, 33, 44, 55}; //declaration plus full initialization
int rat[5]={66, 77}; //declaration with partial initialization
int bat[ ]={12, 23, 34, 45, 56}; //declaration with implicit size and full initialization
int numbers[SIZE];
int i; //loop var
//get input for array cat
for (i=0; i<5; i++)
{
cout<<"Enter an integer => ";
cin>>cat[i]; //see how get input for cat[i]
}
//output arrays
for (i=0; i<5; i++)
{
cout<<"cat["<<i<<"] is " << cat[i]<<endl; //changed by sirisha.
}
/***********************************************************************
This part is for you:
(1) Write a loop to get values from the user for array numbers[SIZE].
(2) After (1), then ask the user to enter an value
(3) Decide whether the value entered by the user at (2) is
in the array numbers[SIZE] or not
***********************************************************************/
//Write Your code here
int c;
for(c=0; c<10; c++)
{
cout << "Enter an interger => ";
cin>>numbers[c];
}
if (c<=10)
{
cout<<"The value entered by the user is in the array numbers"<<numbers[c]<<endl;
}
else
cout<<"The value entered by the user is not in the array numbers"<<endl;
//well done and exit
return 0;
}