Create an array that contains a list of 100 valid charge numbers. Assume the arr
ID: 3696207 • Letter: C
Question
Create an array that contains a list of 100 valid charge numbers. Assume the array contains the charge numbers. Let the user enter a charge number. The program should determine if the number is valid by checking for it in the array you created. A simple linear search should be used to locate the number entered by the user. If the user enters a number that is in the array, the program should cout << a message saying the number is valid. If the user enters a number that is not in the array, the program should cout << a message indicating the number is invalid.
Explanation / Answer
//
// File: LinearSearchArray.cc
// Author: RAM
//
// Created on 30 April, 2016, 10:33 AM
//
#include <stdlib.h>
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
//
//
//
int main() {
int chargeNumubers[100],i,numofElem ,ElemtoSearch, flag=0;
cout<<"Enter Number of Elements to Store as Charge Numbers"<<endl;
cin>> numofElem;
//Enter Elements into array
cout<<"Enter ChargeNumbers "<<endl;
for(i=0;i<=numofElem;i++){
cin>>chargeNumbers[i];
}
//charge Number to search
cout<<"Which Charge Number you want to search"<<endl;
cin>>ElemtoSearch;
//searching element in the array
for(i=1;i<=numofElem;i++){
if(chargeNumbers[i]==ElemtoSearch){
cout<<"The number is Valid"<<endl;
flag=1;
break;
}
}
if(flag==0){
cout<<"The number is Invalid"<<endl;
}
return (0);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.