Problem With Arrays

Hey Guys! I'm trying to get this program to output the balance of an account, when an account number is input. It compiles fine, but doesn't run properly. 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
//FindBal.cpp
//Arrays

#include <iostream>
using namespace std;

void FindBal( int id[5], float bal[5], float idtofind, int & found, float & result)
{
    int pos = 0;
    
    while(pos <= 6 || pos >= 0)
    {
        if(idtofind == id[pos])
        {
          bal = &bal[pos];
          found = true;
        }
       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;
    }
}
Just a quick look, but I think your issue is on line 15. bal s/b result?
closed account (48T7M4Gy)
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
//FindBal.cpp
//Arrays

#include <iostream>

using namespace std;

int main()
{
    int id[5] = { 123, 234, 333, 401, 500 };
    float bal[5] = { 0.0, 100.0, 250.0, 50.0, 1225.0 };
    
    int idtofind = 0, index = 0, selected = 0;
    
    cout << "ID to find? ";
    cin >> idtofind;
    
    while ( index < 5 )
    {
        if ( id[index] == idtofind )
            cout << bal[index];
        
        index++;
    }
    
    return 0;
}
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/beginner/179614/

Multiple posts are bad
closed account (48T7M4Gy)
result = bal[pos];
Topic archived. No new replies allowed.