Question

*Suppose I have a C++ Text File That Looks Like This:* Text File: 10 20 30...

*Suppose I have a C++ Text File That Looks Like This:*

Text File:

10 20 30 40

11 40 50 60

12 50 60 70

I want to be able to read the 3rd column which have the numbers "30 , 50, 60" and find their average. How do I read data from a text file in columns instead of rows?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

code

#include<iostream>
#include<fstream>

using namespace std;

int main()
{
   int sum=0;
   int num1,num2,num3,num4,count=0;
   ifstream inFile;
   inFile.open("Numbers.txt");
   while(inFile)
   {
       inFile>>num1>>num2>>num3>>num4;
       sum+=num3;
       count++;
   }
   cout<<"Average of third column number is: "<<double(sum)/double(count)<<endl;
}

output

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
*Suppose I have a C++ Text File That Looks Like This:* Text File: 10 20 30...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT