a easy question about read and print

I

icegokimo

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!!
 
G

Gavin Deane

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-lite/how-to-post.html#faq-5.8

Also have a look at
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.2

Gavin Deane
 
G

Gavin Deane

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-lite/how-to-post.html#faq-5.8

Also have a look at
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.2

Gavin Deane
 
S

Salt_Peter

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?
 
F

Frederick Gotham

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

osmium

Frederick Gotham said:
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.
 
B

BobR

I would have expected a grade of 'F' in a C++ course!

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.


Magic numbers? 'i' don't get it.

Hey, I entered "-#@&$" here!!

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.) ]
 

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,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top