// here is an example to point you in the right direction
// include statments
int main()
{
ifstream in;// to acces the file with the data information
char ch; // to get the letter
int i = 0; // to eat the calories
int sum = 0; // total calories
in.open("filename");
// check if the file is open
// if not print a message that say id did not open
// if file opened
// while loop
while (!in.eof()) // this will run until it reaches the end of file
{
// read the charachter;
// read the calories;
in.ignore(100, '\n'); // this is to ignore everything after the calories all the way to new line
// add the calories to sum
}
// output the sum
return 0;
}
this is all you should need, so put an effort and if you get stuck or have errors post the effort and someone will help you.
Here is your program that first asks which entry to show, prints it along with total calorie count, then shows the list as a whole, with the sum of all the calories.
I made meal.dat larger. Added also. as first entry, how many entries there are.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
15
A 100
B 515
C 45
D 520
E 128
F 421
G 79
H 170
I 625
J 99
K 395
L 135
M 466
N 649
O 199