Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > lowest number

Reply
Thread Tools

lowest number

 
 
Randi
Guest
Posts: n/a
 
      11-12-2003
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


 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      11-12-2003
"Randi" <> 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



 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      11-12-2003
"Randi" <> 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



 
Reply With Quote
 
Grzegorz Sakrejda
Guest
Posts: n/a
 
      11-12-2003
On Wed, 12 Nov 2003 02:50:59 GMT, Randi <> 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
 
Reply With Quote
 
Randi
Guest
Posts: n/a
 
      11-12-2003
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" <> wrote in message
news:bohsb.128304$9E1.638773@attbi_s52...
> "Randi" <> 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
>
>
>



 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      11-12-2003
"Randi" <> 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" <> wrote in message
> news:bohsb.128304$9E1.638773@attbi_s52...
> > "Randi" <> 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
> >
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sort a number highest to lowest rhitz1218@gmail.com C Programming 17 12-11-2006 04:25 AM
the lowest number of comparisons in string matching laura C Programming 2 09-22-2006 03:35 PM
OT: Number Nine, Number Nine, Number Nine FrisbeeŽ MCSE 37 09-26-2005 04:06 PM
New Zealand, on the other hand, has one of the lowest growth rates and one of the lowest levels of broadband penetration in the world. punlic NZ Computing 6 05-02-2004 10:28 AM
Re: lowest number Randi C++ 4 11-12-2003 12:33 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57