Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do i search a parallel array and then add the array

Status
Not open for further replies.

ggreg

Programmer
Mar 9, 2001
201
US
I have a data file like below
called num.txt
tom#3
sam#10
dave#4
I need for a user to enter names and get a total on the numbers........
if they enter the names tom and dave.....then I
want the 3 and 4 to add together and show me 7
Thanks for any help!
 
ifstream in("num.txt")

int total = 0;
char buffer[128];
in.getline(buffer,128,'#');
// buffer contains name
// add name to array

in.getline(buffer,128);
// buffer contains value
total += atoi(buffer);

Put it in a loop and you should be good to go

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top