3 Replies - 1330 Views - Last Post: 21 September 2011 - 06:54 AM Rate Topic: -----

#1 jayvato01  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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:

:code:

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  Icon User is offline

  • D.I.C Regular

Reputation: 67
  • View blog
  • 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?
Was This Post Helpful? 0
  • +
  • -

#3 jayvato01  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6245
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1