68 780
Assignments Done
98,8%
Successfully Done
In January 2019

# Answer to Question #71516 in C++ for niru

Question #71516
Write a program that lets the user enter a charge account number. The program should determine if the number is valid by checking for it in the following list:
5658845 8080152 1005231 4520125 4562555 6545231
7895122 5552012 3852085 8777541 5050552 7576651
8451277 7825877 7881200 1302850 1250255 4581002
Initialize a one-dimensional array with these values. Then use a simple linear search to locate the number entered by the user. If the user enters a number that is in the array, the program should display a message saying the number is valid. If the user enters a number not in the array, the program should display a message indicating it is invalid.
#include <iostream>

int main()
{
int array[] = {5658845, 8080152, 1005231, 4520125, 4562555, 6545231, 7895122, 5552012, 3852085, 8777541, 5050552,
7576651, 8451277, 7825877, 7881200, 1302850, 1250255, 4581002};
const int n = sizeof(array) / sizeof(array[0]);

std::cout << "Enter number: ";
int number = 0;
std::cin >> number;

for (int i = 0; i < n; ++i)
{
if (array[i] == number)
{
std::cout << "This number is valid" << std::endl;
return 0;
}
}
std::cout << "This number is invalid" << std::endl;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!