473,322 Members | 1,806 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,322 software developers and data experts.

a easy question about read and print


How to write a program that reads in five integers and determines and
prints the largest and the smallest integers in the group?

plz give me an example.Thank you!!

Oct 24 '06 #1
8 2945

icegok...@yahoo.com.tw wrote:
How to write a program that reads in five integers and determines and
prints the largest and the smallest integers in the group?

plz give me an example.Thank you!!
Do you know how to do user input?
Do you know how to find min and max values in a sequence?
Do you know how to do output?
You haven't given us much idea of what you know already.

I'll start you off

int main()
{
// Read five integers and store them somewhere
// Identify the maximum value stored
// Identify the minimum value stored
// Print out the maximum and minimum values
}

If you have trouble turning any one of those four concepts into C++
code, post the code you are having trouble with following all the
guidelines here:
http://www.parashift.com/c++-faq-lit...t.html#faq-5.8

Also have a look at
http://www.parashift.com/c++-faq-lit...t.html#faq-5.2

Gavin Deane

Oct 24 '06 #2

icegok...@yahoo.com.tw wrote:
How to write a program that reads in five integers and determines and
prints the largest and the smallest integers in the group?

plz give me an example.Thank you!!
Do you know how to do user input?
Do you know how to find min and max values in a sequence?
Do you know how to do output?
You haven't given us much idea of what you know already.

I'll start you off

int main()
{
// Read five integers and store them somewhere
// Identify the maximum value stored
// Identify the minimum value stored
// Print out the maximum and minimum values
}

If you have trouble turning any one of those four concepts into C++
code, post the code you are having trouble with following all the
guidelines here:
http://www.parashift.com/c++-faq-lit...t.html#faq-5.8

Also have a look at
http://www.parashift.com/c++-faq-lit...t.html#faq-5.2

Gavin Deane

Oct 24 '06 #3

ic*******@yahoo.com.tw wrote:
How to write a program that reads in five integers and determines and
prints the largest and the smallest integers in the group?

plz give me an example.Thank you!!
How? by starting your compiler or dev environment and writing the
appropriate code to initialize objects and functions. What have you got
so far?

Oct 24 '06 #4
ic*******@yahoo.com.tw wrote:
How to write a program that reads in five integers and determines and
prints the largest and the smallest integers in the group?

plz give me an example.Thank you!!
http://www.parashift.com/c++-faq-lit...t.html#faq-5.2

- J.
Oct 24 '06 #5
Icegokimo posted:
How to write a program that reads in five integers and determines and
prints the largest and the smallest integers in the group?

plz give me an example.Thank you!!

Hey dude! I had this assignment myself just recently... got an A! Here's
the code:

#INCLUDE "iostream.h"

using std { cout, cin };

void main()
{
int[5] arr;

int min = INT_MAX,max = 0;

for(i = arr; i < 5; i++)
{
cout << "Enter Number: ";
cin >i;

if (i<min) min = i;
if (i>max) max = i;
}

cout << "Smallest: " << min
<< "Biggest: " << max;
}

Compiles with zero errors and zero warning on all conforming compilers!
Runs like a jem! Hope that helps.

--

Frederick Gotham
Oct 24 '06 #6
"Frederick Gotham" writes:
>How to write a program that reads in five integers and determines and
prints the largest and the smallest integers in the group?

plz give me an example.Thank you!!


Hey dude! I had this assignment myself just recently... got an A! Here's
the code:

#INCLUDE "iostream.h"

using std { cout, cin };

void main()
{
int[5] arr;

int min = INT_MAX,max = 0;
I would expect a problem if the user enters all negative numbers.
for(i = arr; i < 5; i++)
{
cout << "Enter Number: ";
cin >i;

if (i<min) min = i;
if (i>max) max = i;
}

cout << "Smallest: " << min
<< "Biggest: " << max;
}

Compiles with zero errors and zero warning on all conforming compilers!
Runs like a jem! Hope that helps.

Oct 24 '06 #7
osmium posted:
> int min = INT_MAX,max = 0;

I would expect a problem if the user enters all negative numbers.
Wups, should have written:

int min = INT_MAX, max = INT_MIN;

--

Frederick Gotham
Oct 24 '06 #8
>"Frederick Gotham" writes:
>Hey dude! I had this assignment myself just recently... got an A! Here's
the code:

#INCLUDE "iostream.h"
I would have expected a grade of 'F' in a C++ course!
>using std { cout, cin };

void main(){
Maybe even less than an 'F'!! (int main(){ return 0;})
> int[5] arr;
int min = INT_MAX,max = 0;

I would expect a problem if the user enters all negative numbers.
I would expect a joke to have a smiley :-}, or a grin <G>.
>
> for(i = arr; i < 5; i++){
Magic numbers? 'i' don't get it.
> cout << "Enter Number: ";
cin >i;
Hey, I entered "-#@&$" here!!
>>
if (i<min) min = i;
if (i>max) max = i;
}

cout << "Smallest: " << min
<< "Biggest: " << max;
}

Compiles with zero errors and zero warning on all conforming compilers!
Runs like a jem! Hope that helps.
On Comeau? Did you mean, "It runs like a JAM." (more like 'jelly').

I think what you were trying to show was:

void Painfull(int ouch){
while(true){ for(;;){ Painfull(++ouch);}}
return;
}

int main(){
Painfull(42);
return 0;
}

Pass that one through your "conforming compiler"! <G>

Sorry Fred. The devil made me do it!!
(pretty mean, Fred!! Do you also pull the wings off of flies? :-} )

[ Thanks for the use of your post, osmium. (I didn't load that message.) ]
--
Bob R
POVrookie
Oct 24 '06 #9

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

Similar topics

6
by: JW | last post by:
I'm displaying product thumbnails with brief descriptions on web pages. Clicking on the product does a javascript popup with larger image and detailed description info passed to the javascript...
9
by: Hans-Joachim Widmaier | last post by:
Hi all. Handling files is an extremely frequent task in programming, so most programming languages have an abstraction of the basic files offered by the underlying operating system. This is...
1
by: asdsd sir | last post by:
Hi!I'm new in Python and i'd like to ask some general questions about stdin,stdout... Firstly... if we type like something like : cat "file.txt"|python somefile.py #somefile.py import sys
5
by: f pemberton | last post by:
I have kind of an interesting string, it looks like a couple hundred letters bunched together with no spaces. Anyway, i'm trying to put a "?" and a (\n) newline after every 100th character of the...
2
by: oyster | last post by:
I find that the existing email moudle is some hard for me to understand, especially the part of how to set the CC, BCC and attach the files. Is there any more easy one like this p-code? import...
1
by: NevilleDNZ | last post by:
Hi, Apologies first as I am not a unicode expert.... indeed I the details probably totally elude me. Not withstanding: how can I convert a binary string containing UTF-8 binary into a python...
4
by: OhKyu Yoon | last post by:
Hi! I have a really long binary file that I want to read. The way I am doing it now is: for i in xrange(N): # N is about 10,000,000 time = struct.unpack('=HHHH', infile.read(8)) # do...
6
by: happy | last post by:
you can take a look for this web sites http://www.imanway.com/vb/forumdisplay.php?f=90 http://www.geocities.com/islamone_l/index.htm or read this ...
2
by: jalanb3 | last post by:
Evening all, And thank you for your valuable reading skills. The following pattern turned up in coding tonight. It works, but I'm suspicious, it just seems too easy. So any comments or...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.