By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,820 Members | 1,154 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,820 IT Pros & Developers. It's quick & easy.

lowest number

P: n/a
I am having problems with this question: Write a C++ while statement that
will input numbers from a file until the end of file is reached. Output the
lowest number in the file.

Ok, I do understand the logic, I believe the following for loop solves it
from keyboard input. But how do you point to any given value from a file.
You can't assign anything to a variable. Little lost on this one.

Thanks,
Kelsey
Jul 19 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"Randi" <RS******@stny.rr.com> wrote...
I am having problems with this question: Write a C++ while statement that
will input numbers from a file until the end of file is reached. Output the lowest number in the file.
There is no question here. It looks much more like an assignment.
Have you tried asking your teacher about it?
Ok, I do understand the logic, I believe the following for loop solves it
from keyboard input.
Which "following for loop" are you talking about?
But how do you point to any given value from a file.
You can't assign anything to a variable. Little lost on this one.


To input something from a file you need to open a file. Read about
ifstream class in your textbook.

Victor

Jul 19 '05 #2

P: n/a
"Randi" <RS******@stny.rr.com> wrote...
I am having problems with this question: Write a C++ while statement that
will input numbers from a file until the end of file is reached. Output the lowest number in the file.
There is no question here. It looks much more like an assignment.
Have you tried asking your teacher about it?
Ok, I do understand the logic, I believe the following for loop solves it
from keyboard input.
Which "following for loop" are you talking about?
But how do you point to any given value from a file.
You can't assign anything to a variable. Little lost on this one.


To input something from a file you need to open a file. Read about
ifstream class in your textbook.

Victor

Jul 19 '05 #3

P: n/a
On Wed, 12 Nov 2003 02:50:59 GMT, Randi <RS******@stny.rr.com> wrote:
I am having problems with this question: Write a C++ while statement that
will input numbers from a file until the end of file is reached. Output
the
lowest number in the file.

Ok, I do understand the logic, I believe the following for loop solves it
from keyboard input. But how do you point to any given value from a
file.
You didn't write anything here.
Start with a function :

int min_number(istream& is) {
// istream contains integer>0 numbers up to the end
int i(1000); // all numbers suppose to be smaller then 1000 while(is) {
// you can read anything if "is" is good
int j;
is >> j; // attempt to read the number
if(is) // if you read the number "is" state should be good
if(j<i) i=j;
} // end of while
return i; // if the file is no good any more
}
You can't assign anything to a variable. Little lost on this one.
Don't know what you mean, use >> operator.

Thanks,
Kelsey

--
grzegorz
Jul 19 '05 #4

P: n/a
Whoa there,
I am not a kid trying to get an answer for an assignment. I am a 38 year
old student taking my required C++ class for my IT degree. I am also a
member of Phi Theta Cappa with a 3.8 GPA, trying to study for an exam
tomorrow. These are practice problems to help us study. Here is my code
for the for loop. How would you make this work taking input from a file.

Thanks,
Kelsey

"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:bohsb.128304$9E1.638773@attbi_s52...
"Randi" <RS******@stny.rr.com> wrote...
I am having problems with this question: Write a C++ while statement that will input numbers from a file until the end of file is reached. Output

the
lowest number in the file.


There is no question here. It looks much more like an assignment.
Have you tried asking your teacher about it?
Ok, I do understand the logic, I believe the following for loop solves it from keyboard input.


Which "following for loop" are you talking about?
But how do you point to any given value from a file.
You can't assign anything to a variable. Little lost on this one.


To input something from a file you need to open a file. Read about
ifstream class in your textbook.

Victor

Jul 19 '05 #5

P: n/a
"Randi" <RS******@stny.rr.com> wrote...
Whoa there,
I am not a kid trying to get an answer for an assignment. I am a 38 year
old student taking my required C++ class for my IT degree. I am also a
member of Phi Theta Cappa with a 3.8 GPA, trying to study for an exam
tomorrow. These are practice problems to help us study. Here is my code
for the for loop. How would you make this work taking input from a file.
I am sorry, Kelsey [or "Randi", or whatever],

With all due respect to your age, effort, and prior achievements,
you seem to be missing an important part of this whole newsgroup
thing. If you want others to see your code and recommend how to
change it, you _got_to_post_it_. I can't see a damn thing. Stop
writing "here is my code" and just copy and paste the code into
the message.

We can try to figure this one out, you just need to help us help you.

BTW, have you already read about 'ifstream' as I suggested?

(and it's Phi Theta _K_appa, isn't it? Just checking...)

Thanks,
Kelsey

"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:bohsb.128304$9E1.638773@attbi_s52...
"Randi" <RS******@stny.rr.com> wrote...
I am having problems with this question: Write a C++ while statement that will input numbers from a file until the end of file is reached.
Output
the
lowest number in the file.


There is no question here. It looks much more like an assignment.
Have you tried asking your teacher about it?
Ok, I do understand the logic, I believe the following for loop solves

it from keyboard input.


Which "following for loop" are you talking about?
But how do you point to any given value from a file.
You can't assign anything to a variable. Little lost on this one.


To input something from a file you need to open a file. Read about
ifstream class in your textbook.

Victor


Jul 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.