# Reads non-zero integers, calculates difference between highest and low

Page 1 of 1

## 3 Replies - 1330 Views - Last Post: 21 September 2011 - 06:54 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=247963&amp;s=4001e5fbfcd01241814eb9dc51434cf6&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 jayvato01

Reputation: 0
• Posts: 3
• Joined: 20-September 11

# Reads non-zero integers, calculates difference between highest and low

Posted 20 September 2011 - 08:09 PM

```#include <iostream>
using namespace std;
int main()
{
int num, max, min;
cout << "Enter a number";
cin >> num;

max = num, min = num;
while (num !=0);

{
if (num > max) max = num;
if (num < min) min = num;

cout << "Enter a number";
cin >> num;
}

cout << "The max is " << max << endl;
cout << "The Min is " << min << endl;
cout << "The difference between max and  min is " << (max - min);

system("pause");
return 0;

}
```

well this program should use a while loop structure, It needs to read a list of non zero integers from te standard input device and calculates and displays the difference between the largest and the smallest of these calues. The program should end when a 0 value is read. This final value 0 will not participate in the required calculation.
at the moment all it does it show the cout bit and doesn't compile anything else/

MOD EDIT: Fixed code tags. The RIGHT way to use code tags:

This post has been edited by JackOfAllTrades: 21 September 2011 - 06:53 AM

Is This A Good Question/Topic? 0

## Replies To: Reads non-zero integers, calculates difference between highest and low

### #2 Coding in the name of

• D.I.C Regular

Reputation: 67
• Posts: 291
• Joined: 07-July 10

## Re: Reads non-zero integers, calculates difference between highest and low

Posted 20 September 2011 - 08:16 PM

What errors are you getting?

### #3 jayvato01

Reputation: 0
• Posts: 3
• Joined: 20-September 11

## Re: Reads non-zero integers, calculates difference between highest and low

Posted 20 September 2011 - 08:28 PM

When I compile the program, it says "enter a number" but when I do then it shows nothing after. view my above comment for the question.

• Saucy!

Reputation: 6245
• Posts: 24,013
• Joined: 23-August 08

## Re: Reads non-zero integers, calculates difference between highest and low

Posted 21 September 2011 - 06:54 AM

```while (num !=0);
```

The semi-colon at the end of that while just creates an infinite loop. Your program never progresses beyond that point.