Im trying to make a program with an external .txt file. It should contain
First name, last name and the age of the persons. Then get the info from the .txt-file and print the information, sum all the ages and then count the average age.
I don't know how to count the number of integers so I can calculate the average
age. Should I save the information in another way? (Im a rookie). Help me please! Should i use a for-loop in some kind of way?
just count them as you read them.
unsignedint count = 0;
while (inFile >> name >> lname >> age)
{
cout <<name<<" "<<lname <<" "<<endl<<age<< '\0'<<endl<<endl;
sum = sum + age;
count ++;
}
I have a problem with calculating the new average and sum of the ages when I add more students. And when I press 2 in "How many students do you want to add?"
The "Enter name" and "Enter last name" shows up at the same time, something wrong with the for-loop?
The program is supposed to take the full name in one string but I don't know how?