So I need to make a bank account program,and at one point I need to have the user input an ID to check if there is an account with the same number in the arrays. I am completely lost and don't know how to go about it.
I already have the 3 set of ID's along with the 2nd set of balances on a notepad
file using fstream.
Your function, int findacct(int acctnum_array[],int num_accts,int account), has 3 parameters.
The first one is the array you want to look through.
The second on how many accounts are within the array.
The last one is the account to search for.
So try this in your main, (replacing the < >, with what you have called them.
That worked it now asks for a number and if I put a number in regardless what it is doesn't say "found" and it asks for another number that responds with "not found".
try and use the standard library algorithms wherever possible, like in this case std::find() could do the job:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
#include <algorithm>
#include <iterator>
int main()
{
int acctnum_array[] {123, 456, 789, 1011, 1213, 1415};
std::cout << "Enter a/c number to search: \n";
int n1{};
std::cin >> n1;
auto result1 = std::find(std::begin(acctnum_array), std::end(acctnum_array), n1);
std::cout << ((result1 != std::end(acctnum_array)) ? "found \n" : "not found \n");
}
//http://en.cppreference.com/w/cpp/algorithm/find
the benefit of using the standard library algorithms is that (a) they can be used alongside other standard library components like containers and iterators and (b) they are more robust having gone through the whole C++ peer-review process