| | |
Help with calculating avrg from input file.
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
How about:
c Syntax (Toggle Plain Text)
int total=0; while (inFile) { total += ctemp; // .... }
Last edited by John A; Mar 27th, 2007 at 7:12 pm. Reason: whoops, forgot to initalize total!
"Technological progress is like an axe in the hands of a pathological criminal."
All my posts may be freely redistributed under the terms of the MIT license.
All my posts may be freely redistributed under the terms of the MIT license.
•
•
•
•
ok. almost there, what about the line counter waltp suggested so that i could calculate the average?? how do i incorporate that
C++ Syntax (Toggle Plain Text)
int counter=0; // increment this inside the loop, add +1 after the loop
"Technological progress is like an axe in the hands of a pathological criminal."
All my posts may be freely redistributed under the terms of the MIT license.
All my posts may be freely redistributed under the terms of the MIT license.
•
•
Join Date: Mar 2007
Posts: 10
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
int total=0; int count=0; while (inFile) //End-ofFile Controlled Loop { total += ctemp; (total=1; total<25; total++) outFile << "\t" << ref << "\t" << mydate << "\t" << Celsius(ctemp) << "°F" << endl << endl; // Write Record inFile >> ref >> mydate >> ctemp; // Read File (count=1; count<25; ) } count++; average= total/count;
it should be something like that, i imagine, i must be bugging the hell outta u joeprogrammer, for that im sorry:rolleyes:. Its simply because up till now i havent done any programs that require counters of any sort, just very basic stuff, and the logic escapes me but thanks for your patience.
Last edited by swordy06; Mar 27th, 2007 at 9:22 pm.
Put the incrementation inside the loop. And what are these lines supposed to do?
Here's how it should look:
And you don't need to worry about bugging me, we were all newbies once.
C++ Syntax (Toggle Plain Text)
(total=1; total<25; total++) (count=1; count<25; )
Here's how it should look:
C++ Syntax (Toggle Plain Text)
int total=0; int count=0; while (inFile) //End-ofFile Controlled Loop { total += ctemp; ++count; outFile << "\t" << ref << "\t" << mydate << "\t" << Celsius(ctemp) << "°F" << endl << endl; // Write Record inFile >> ref >> mydate >> ctemp; // Read File } ++count; average= total/count;
And you don't need to worry about bugging me, we were all newbies once.
"Technological progress is like an axe in the hands of a pathological criminal."
All my posts may be freely redistributed under the terms of the MIT license.
All my posts may be freely redistributed under the terms of the MIT license.
•
•
Join Date: Mar 2007
Posts: 10
Reputation:
Solved Threads: 0
nevermind those 2 lines, it didnt make sense to include them, ok, i have a problem, the counter runs fine, but it is taking the temperatures from the input file, i need it to count the temperatures from the output file since those are the temperatures already converted how can i make the counter so that it counts the already converted temperatures??
I imagine it might be done with another decision?
while (inFile)
{ total += ctemp // .....
I imagine it might be done with another decision?
while (inFile)
{ total += ctemp // .....
Last edited by swordy06; Mar 27th, 2007 at 11:00 pm.
•
•
•
•
I thought i had to define the number of lines within the input file, and i used that from another example code that i saw,
- (total=1; total<25; total++)
- (count=1; count<25; count++)
thats probably not the right way to do it.
C++ Syntax (Toggle Plain Text)
for (int i=0; i < x; ++i) { // blah blah }
The part that actually does the incrementation is the last statement,
++i. All the rest is just loop-related stuff. "Technological progress is like an axe in the hands of a pathological criminal."
All my posts may be freely redistributed under the terms of the MIT license.
All my posts may be freely redistributed under the terms of the MIT license.
•
•
Join Date: Mar 2007
Posts: 10
Reputation:
Solved Threads: 0
i have a problem, the counter runs fine, but it is taking the temperatures from the input file, i need it to count the temperatures from the output file since those are the temperatures already converted how can i make the counter so that it counts the already converted temperatures??
I imagine it might be done with another decision?
while (inFile)
{ total += ctemp // .....
I imagine it might be done with another decision?
while (inFile)
{ total += ctemp // .....
Convert the amount to celsius before you add it onto the total. (not tested)
C++ Syntax (Toggle Plain Text)
int total=0; int count=0; int celsiusTemp; while (inFile) //End-ofFile Controlled Loop { celsiusTemp = Celsius(ctemp); // convert it to celsius beforehand total += celsiusTemp; ++count; // don't have to call 'Celsius' here, use the variable 'celsiusTemp' outFile << "\t" << ref << "\t" << mydate << "\t" << celsiusTemp << "°F" << endl << endl; // Write Record inFile >> ref >> mydate >> ctemp; // Read File } ++count; average= total/count;
"Technological progress is like an axe in the hands of a pathological criminal."
All my posts may be freely redistributed under the terms of the MIT license.
All my posts may be freely redistributed under the terms of the MIT license.
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: Binary Recursion Function Errors - Help!!
- Next Thread: Structure in Maps
Views: 3135 | Replies: 21
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






