Question
Hello, I need help with c++ and will try my best to explain the problem. I don't need a whole code written, just some help
Hello, I need help with c++ and will try my best to explain the problem. I don't need a whole code written, just some help on my output. Basically i have to read in data from a text file and print out data. Below is my code and the text file im reading in from, probably not the best coding you'll see but I'm not an expert.
#include
while (in >> i >> prog[i].totallines >> prog[i].totalcomments) //while line in has the i programmer number, prog i numb lines, prog i comments, do this { LinesOfCode(i, prog[i].totallines, prog[i].totalcomments); //call lines of code to count total lines of comments and lines printEachTime(); //print each time to print each persons progress } print(); //print final results, should also call the function that sees how many people it would take to reach 1000 in.close(); out.close();
system("pause"); return 0; }
void LinesOfCode(int a, int b, int c){ int temp=a; //set temp equal to programmer number int templines=b; //set this equal to the programmers total lines int tempcomments=c; //set this equal to programmers total comments while (prog[temp].totallines
tempcomments += prog[temp].totalcomments; prog[temp].totalcomments = tempcomments;
//printEachTime(); break; } }
void printEachTime() { //for printing out the persons information each time ifstream in; ofstream out; in.open("Text.txt"); //open this files out.open("output.txt"); int m = 1;
cout
TEXT FILE:
10 230 100 8 206 120 7 111 50 3 159 56 9 336 200 1 51 10 10 250 123 4 101 29 9 341 190 2 105 43 8 256 122 10 320 120 3 150 19 5 215 98 7 222 108 9 400 210 10 330 125
basically my issue is, the output doesnt start with the first line in the text file. Each line for the output doesnt correspond to the right line in the text file. For example in line 1 of the data file its 10 230 and 100, in the output it says 10, 206, 120; which is the seconds line information in the input file. Hope that makes sense.
Please help me resolve the issue.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started