473,385 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

help with my c++ example

Hi to all!

I have to write the following program.

1.User inputs a number (example: 5)
2.Then (because he entered 5) he enters 5 times, each time different,
3-placed number (example: 134, 256, 425, 253, 275)
3.then I have to find the lowest of those he entered and print it out

I have no idea how do I do that, because If the user enters a mubers
100 so he will input 100 different 3-placed numbers.you have to
declare each number (example: int a = 1;...)so that would mean that i
need to declare 100ints!! but thats impossible, what if the user
decides he is going to input 1000000 different 3-placed numbers?

help me out, please
Jul 22 '05 #1
13 1588

"vbmax" <bs*****@yahoo.com> wrote in message
news:4d**************************@posting.google.c om...
Hi to all!

I have to write the following program.

1.User inputs a number (example: 5)
2.Then (because he entered 5) he enters 5 times, each time different,
3-placed number (example: 134, 256, 425, 253, 275)
3.then I have to find the lowest of those he entered and print it out

I have no idea how do I do that, because If the user enters a mubers
100 so he will input 100 different 3-placed numbers.you have to
declare each number (example: int a = 1;...)so that would mean that i
need to declare 100ints!! but thats impossible, what if the user
decides he is going to input 1000000 different 3-placed numbers?

help me out, please


No, all you need is two variables. One for the last number the user entered
and one for the LOWEST NUMBER FOUND SO FAR. Each time the user enters a new
number check if it is lower than the lowest number entered so far and if it
is update the lowest number entered so far.

When the user has entered all the numbers then the lowest number found so
far will be the lowest number of all the numbers entered.

john
Jul 22 '05 #2

"vbmax" <bs*****@yahoo.com> schrieb im Newsbeitrag
news:4d**************************@posting.google.c om...
Hi to all!

I have to write the following program.

1.User inputs a number (example: 5)
2.Then (because he entered 5) he enters 5 times, each time different,
3-placed number (example: 134, 256, 425, 253, 275)
3.then I have to find the lowest of those he entered and print it out

I have no idea how do I do that, because If the user enters a mubers
100 so he will input 100 different 3-placed numbers.you have to
declare each number (example: int a = 1;...)so that would mean that i
need to declare 100ints!! but thats impossible, what if the user
decides he is going to input 1000000 different 3-placed numbers?

help me out, please


Start out and nail the problem down to the basic question. You have an input
(1 variable) and you should find the lowest number (another variable) that
the user entered. One way would be to store all variables and perform the
test for the lowest number afterwards. This can certainly be done with a
dynamic array or a standard container but is it really necessary?

No, you can simply solve this problem by testing for the lowest number each
time the user inputs another value and consequently you'll only need two
variables. However, there is a pitfall you should keep in mind - think about
the value you'll use to initialize your variables before the user starts
entering values and the comparison is performed for the first time.

BTW - the user will have a hard time finding 1000000 different three digit
numbers ;-)

HTH
Chris

Jul 22 '05 #3

"vbmax" <bs*****@yahoo.com> wrote in message
news:4d**************************@posting.google.c om...
Hi to all!

I have to write the following program.

1.User inputs a number (example: 5)
2.Then (because he entered 5) he enters 5 times, each time different,
3-placed number (example: 134, 256, 425, 253, 275)
3.then I have to find the lowest of those he entered and print it out

I have no idea how do I do that, because If the user enters a mubers
100 so he will input 100 different 3-placed numbers.you have to
declare each number (example: int a = 1;...)so that would mean that i
need to declare 100ints!!
Hint:

int i;
i = 134;
i = 256;
i = 425;
but thats impossible, what if the user
decides he is going to input 1000000 different 3-placed numbers?


Last time I checked, there were only 900 of them. But you don't
need 900 objects.

-Mike
Jul 22 '05 #4
bs*****@yahoo.com (vbmax) wrote in message news:<4d**************************@posting.google. com>...
Hi to all!

I have to write the following program.

1.User inputs a number (example: 5)
2.Then (because he entered 5) he enters 5 times, each time different,
3-placed number (example: 134, 256, 425, 253, 275)
3.then I have to find the lowest of those he entered and print it out

I have no idea how do I do that, because If the user enters a mubers
100 so he will input 100 different 3-placed numbers.you have to
declare each number (example: int a = 1;...)so that would mean that i
need to declare 100ints!! but thats impossible, what if the user
decides he is going to input 1000000 different 3-placed numbers?

help me out, please


I would love to help you. But I do not want to tell you exactly how.
i will point you in the right direction. You are right, you need a
way to handle an arbitrary number of ints. In C you could dynamically
allocate memory for however many ints were asked for with malloc. in
c++ it is easier, there are classes that will do all the dirty work.
The one you want is vector. This will allow you to decide what you
want a vector of and on the fly increase to the size needed. Why dont
you look up vector and come back with more questions

Stuart Gerchick
Jul 22 '05 #5
bs*****@yahoo.com (vbmax) wrote in message news:<4d**************************@posting.google. com>...
Hi to all!

I have to write the following program. [homework snipped] help me out, please


Sure! Glad to help you. I'll just need your instructor's email address
in order to get a few clarifications on how this should be done.
Socks
Jul 22 '05 #6
bs*****@yahoo.com (vbmax) wrote in message news:<4d**************************@posting.google. com>...
Hi to all!

I have to write the following program.

1.User inputs a number (example: 5)
2.Then (because he entered 5) he enters 5 times, each time different,
3-placed number (example: 134, 256, 425, 253, 275)
3.then I have to find the lowest of those he entered and print it out

I have no idea how do I do that, because If the user enters a mubers
100 so he will input 100 different 3-placed numbers.you have to
declare each number (example: int a = 1;...)so that would mean that i
need to declare 100ints!! but thats impossible, what if the user
decides he is going to input 1000000 different 3-placed numbers?

help me out, please


I'll help you figure it out, but I won't answer it for you. that will
get you nowhere...

for the input -> use a for loop
for the 1000000 different numbers -> do you really need that many to
find the lowest one if you're taking them in one at a time?

here's a hint on that second one - let's say I want to read you 100
numbers and have you tell me what the lowest one is... are you going
to memorize every number I read to you?
Jul 22 '05 #7

"Stuart Gerchick" <sg*******@bloomberg.net> wrote in message
news:e2**************************@posting.google.c om...
bs*****@yahoo.com (vbmax) wrote in message news:<4d**************************@posting.google. com>...
Hi to all!

I have to write the following program.

1.User inputs a number (example: 5)
2.Then (because he entered 5) he enters 5 times, each time different,
3-placed number (example: 134, 256, 425, 253, 275)
3.then I have to find the lowest of those he entered and print it out

I have no idea how do I do that, because If the user enters a mubers
100 so he will input 100 different 3-placed numbers.you have to
declare each number (example: int a = 1;...)so that would mean that i
need to declare 100ints!! but thats impossible, what if the user
decides he is going to input 1000000 different 3-placed numbers?

help me out, please


I would love to help you. But I do not want to tell you exactly how.
i will point you in the right direction. You are right, you need a
way to handle an arbitrary number of ints.


No he doesn't.

In C you could dynamically allocate memory for however many ints were asked for with malloc. in
c++ it is easier, there are classes that will do all the dirty work.
The one you want is vector. This will allow you to decide what you
want a vector of and on the fly increase to the size needed. Why dont
you look up vector and come back with more questions


No need to store all the input to solve this.

-Mike

Jul 22 '05 #8
"Mike Wahler" <mk******@mkwahler.net> wrote in message news:<h1*****************@newsread1.news.pas.earth link.net>...
"Stuart Gerchick" <sg*******@bloomberg.net> wrote in message
news:e2**************************@posting.google.c om...
bs*****@yahoo.com (vbmax) wrote in message

news:<4d**************************@posting.google. com>...
Hi to all!

I have to write the following program.

1.User inputs a number (example: 5)
2.Then (because he entered 5) he enters 5 times, each time different,
3-placed number (example: 134, 256, 425, 253, 275)
3.then I have to find the lowest of those he entered and print it out

I have no idea how do I do that, because If the user enters a mubers
100 so he will input 100 different 3-placed numbers.you have to
declare each number (example: int a = 1;...)so that would mean that i
need to declare 100ints!! but thats impossible, what if the user
decides he is going to input 1000000 different 3-placed numbers?

help me out, please


I would love to help you. But I do not want to tell you exactly how.
i will point you in the right direction. You are right, you need a
way to handle an arbitrary number of ints.


No he doesn't.

In C you could dynamically
allocate memory for however many ints were asked for with malloc. in
c++ it is easier, there are classes that will do all the dirty work.
The one you want is vector. This will allow you to decide what you
want a vector of and on the fly increase to the size needed. Why dont
you look up vector and come back with more questions


No need to store all the input to solve this.

-Mike


of course not, not to just get the average. but to do anything more,
you might need it. of course he can just take a sum and divide by the
number of inputs, that is not the point. he obviously is not aware of
a languages ability for anything other than single variables. We
should take this opportunity so he can see a little more and
understand a new concept.
Jul 22 '05 #9

"Stuart Gerchick" <sg*******@bloomberg.net> wrote in message
news:e2**************************@posting.google.c om...
"Mike Wahler" <mk******@mkwahler.net> wrote in message news:<h1*****************@newsread1.news.pas.earth link.net>...
"Stuart Gerchick" <sg*******@bloomberg.net> wrote in message
news:e2**************************@posting.google.c om...
bs*****@yahoo.com (vbmax) wrote in message

news:<4d**************************@posting.google. com>...
> Hi to all!
>
> I have to write the following program.
>
> 1.User inputs a number (example: 5)
> 2.Then (because he entered 5) he enters 5 times, each time different, > 3-placed number (example: 134, 256, 425, 253, 275)
> 3.then I have to find the lowest of those he entered and print it out >
> I have no idea how do I do that, because If the user enters a mubers
> 100 so he will input 100 different 3-placed numbers.you have to
> declare each number (example: int a = 1;...)so that would mean that i > need to declare 100ints!! but thats impossible, what if the user
> decides he is going to input 1000000 different 3-placed numbers?
>
> help me out, please

I would love to help you. But I do not want to tell you exactly how.
i will point you in the right direction. You are right, you need a
way to handle an arbitrary number of ints.


No he doesn't.

In C you could dynamically
allocate memory for however many ints were asked for with malloc. in
c++ it is easier, there are classes that will do all the dirty work.
The one you want is vector. This will allow you to decide what you
want a vector of and on the fly increase to the size needed. Why dont
you look up vector and come back with more questions


No need to store all the input to solve this.

-Mike


of course not, not to just get the average.


But that isnīt what the OP is trying to do.

[cite] 3.then I have to find the lowest of those he entered and print it out
[/cite]
but to do anything more,
you might need it. of course he can just take a sum and divide by the
number of inputs, that is not the point. he obviously is not aware of
a languages ability for anything other than single variables. We
should take this opportunity so he can see a little more and
understand a new concept.


Thatīs certainly true, but one step after the other might be more helpful
because I doubt that the OP will be happy reading about templates and
template syntax etc. if she/he is still stuck with such basic algorithmic
things.

Cheers
Chris
Jul 22 '05 #10
pu*********@hotmail.com wrote in message news:<c7**************************@posting.google. com>...
bs*****@yahoo.com (vbmax) wrote in message news:<4d**************************@posting.google. com>...
Hi to all!

I have to write the following program.

[homework snipped]
help me out, please


Sure! Glad to help you. I'll just need your instructor's email address
in order to get a few clarifications on how this should be done.
Socks


It is my first time to enter into this Google Groups,and I'm so
excited that I write this message although it having nothing to do
with the topic.Thank puppet_socet for providing me a chance to
here,thanks again.
Jul 22 '05 #11
"Chris Theis" <Ch*********@nospam.cern.ch> wrote in message news:<cl**********@sunnews.cern.ch>...
"Stuart Gerchick" <sg*******@bloomberg.net> wrote in message
news:e2**************************@posting.google.c om...
"Mike Wahler" <mk******@mkwahler.net> wrote in message

news:<h1*****************@newsread1.news.pas.earth link.net>...
"Stuart Gerchick" <sg*******@bloomberg.net> wrote in message
news:e2**************************@posting.google.c om...
> bs*****@yahoo.com (vbmax) wrote in message news:<4d**************************@posting.google. com>... > > Hi to all!
> >
> > I have to write the following program.
> >
> > 1.User inputs a number (example: 5)
> > 2.Then (because he entered 5) he enters 5 times, each time different, > > 3-placed number (example: 134, 256, 425, 253, 275)
> > 3.then I have to find the lowest of those he entered and print it out > >
> > I have no idea how do I do that, because If the user enters a mubers
> > 100 so he will input 100 different 3-placed numbers.you have to
> > declare each number (example: int a = 1;...)so that would mean that i > > need to declare 100ints!! but thats impossible, what if the user
> > decides he is going to input 1000000 different 3-placed numbers?
> >
> > help me out, please
>
> I would love to help you. But I do not want to tell you exactly how.
> i will point you in the right direction. You are right, you need a
> way to handle an arbitrary number of ints.

No he doesn't.

In C you could dynamically
> allocate memory for however many ints were asked for with malloc. in
> c++ it is easier, there are classes that will do all the dirty work.
> The one you want is vector. This will allow you to decide what you
> want a vector of and on the fly increase to the size needed. Why dont
> you look up vector and come back with more questions

No need to store all the input to solve this.

-Mike


of course not, not to just get the average.


But that isnīt what the OP is trying to do.

[cite] 3.then I have to find the lowest of those he entered and print it out
[/cite]
but to do anything more,
you might need it. of course he can just take a sum and divide by the
number of inputs, that is not the point. he obviously is not aware of
a languages ability for anything other than single variables. We
should take this opportunity so he can see a little more and
understand a new concept.


Thatīs certainly true, but one step after the other might be more helpful
because I doubt that the OP will be happy reading about templates and
template syntax etc. if she/he is still stuck with such basic algorithmic
things.

Cheers
Chris


Agreed. Though it seems even learning about arrays, circa 1960's
Fortran could be useful here
Jul 22 '05 #12
Mike Wahler wrote:
"vbmax" <bs*****@yahoo.com> wrote in message
news:4d**************************@posting.google.c om...

[snip]
but thats impossible, what if the user
decides he is going to input 1000000 different 3-placed numbers?

Last time I checked, there were only 900 of them. But you don't
need 900 objects.

-Mike

Wouldn't that be 1000?
0 ... 999
I believe that is 1000. Did you or I miss some?
--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book

Jul 22 '05 #13

"Thomas Matthews" <Th****************************@sbcglobal.net> wrote in
message news:XU******************@newssvr31.news.prodigy.c om...
Mike Wahler wrote:
"vbmax" <bs*****@yahoo.com> wrote in message
news:4d**************************@posting.google.c om...

[snip]
but thats impossible, what if the user
decides he is going to input 1000000 different 3-placed numbers?

Last time I checked, there were only 900 of them. But you don't
need 900 objects.

-Mike

Wouldn't that be 1000?
0 ... 999
I believe that is 1000. Did you or I miss some?


I suppose OP would need to clarify what he meant by '3-placed'.
I took it to mean "three digits". No leading zeros.

-Mike
Jul 22 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Alan Bashy | last post by:
Please, guys, In need help with this. It is due in the next week. Please, help me to implement the functions in this programm especially the first three constructor. I need them guys. Please, help...
4
by: MLH | last post by:
Access 97 has left examples out of much of HELP that was included in Access 2.0. Anybody know why? Or better still, where to find examples. For example, Access 97 has no example code in its...
13
by: Chua Wen Ching | last post by:
Hi there, I saw this article here in vb.net. http://www.error-bank.com/microsoft.public.dotnet.languages.vb.1/148992_Thread.aspx and ...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
0
by: Kermitus | last post by:
Hey I was hoping for a little help. I am a Domain reseller for Aplus.net. The problem is they really don't provide an API to automate Domain searches, registering etc... I see much potential in...
1
by: girthyvhf | last post by:
Hello all, I am trying to use the example for encrypting connection strings called: How To: Build And Run the Protected Configuration Provider Example. This is located in VS 2005 help at: ...
16
by: pamelafluente | last post by:
I am still working with no success on that client/server problem. I need your help. I will submit simplified versions of my problem so we can see clearly what is going on. My model: A client...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
5
by: ibid | last post by:
hi every one just wondering if anyone could help sorry if i seem abit dumb but im a newbie to it all ive got to asign a mail program on my auction site in the config.pl files (i think this is the...
12
by: =?Utf-8?B?ZGdvdw==?= | last post by:
I designed a "contact_us" page in visual web developer 2005 express along with EW2 after viewing tutorials on asp.net's help page. Features work like they should, but I cannot figure out how to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.