lowest number

R

Randi

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
 
V

Victor Bazarov

Randi said:
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
 
V

Victor Bazarov

Randi said:
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
 
G

Grzegorz Sakrejda

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.
 
R

Randi

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
 
V

Victor Bazarov

Randi said:
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...)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,374
Latest member
anuragag27

Latest Threads

Top