Arrays: Finding Balance Problem

Hey Guys! My goal is to use a function to output the balance of any given account, so that when an account number is input the balance of that account is given. [Update:] Alright so it runs now, but no matter what I input it always outputs 0. Thoughts?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//FindBal.cpp
//Arrays Assignment

#include <iostream>
using namespace std;

void FindBal( int id[5], float bal[5], float idtofind, int & found, float & result)
{
    int pos = 0;
    int ans = true;
    
    while(ans == true)
    {
        if(pos <= 5 || pos >= 0)
        {
            if(idtofind == id[pos])
            {
            bal =& bal[pos];
            found = true;
                ans = false;
            }
            else
                pos++;
        }
    }
    
}

int main()
{
    int id[5] = { 123, 234, 333, 401, 500 };
    float bal[5] = { 0.0, 100.0, 250.0, 50.0, 1225.0 };
    float result;
    int idtofind, found;
    
    cout << "ID to find? ";
    cin >> idtofind;
    
    while (idtofind > 0)
    {
        FindBal(id, bal, idtofind, found, result);
        if (found)
            cout << "The balance is " << result << endl;
        else
            cout << "Not found";
        
        cout << "ID to find? ";
        cin >> idtofind;
    }
}
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/beginner/179556/

Multiple posts are bad.
Topic archived. No new replies allowed.