Array Assignment

Hey Guys! I'm new to writing programs, and I'm having trouble with writing this function and getting it to execute properly. Any help that can be given will be greatly appreciated.


Okay I changed a few things, but it seems likes it's stuck in loop.. 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
//Alex Barnes
//FindBal.cpp
//Arrays Homework

#include <iostream>
using namespace std;

void FindBal( int id[5], float bal[5], int 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;
    }
}
Last edited on
Lines 10-17: You need a loop here to iterate through the id array.
Topic archived. No new replies allowed.