Question #15254

Write a C++ program with a while loop structure. This program will reads a list of non-zero integers from the standard input device, and displays the largest and the smallest number, and the difference between them. The program will end when a 0 value is read. This final value 0 will not participate in the required calculation. Develop a Defining Diagram (i.e. an IPO Diagram) before writing the program.

PROGRAM SHOULD BE IN WHILE LOOP

PROGRAM SHOULD BE IN WHILE LOOP

Expert's answer

#include <iostream>

using namespace std;

int main()

{

int a,max,min;

cout<<"\n Enter the integers : ";

cin>>a;

max=min=a;

while (a!=0){

cout<<"\n Enter the integers : ";

cin>>a;

if(a!=0){

if (max<a)

max=a;

if (min>a)

min=a;

}

& }

cout<<"max = "<<max<< " \n";

cout<<"min = "<<min<< " \n";

cout<<"max-min= "<<max-min<< " \n\n\n";

system("PAUSE");

}

using namespace std;

int main()

{

int a,max,min;

cout<<"\n Enter the integers : ";

cin>>a;

max=min=a;

while (a!=0){

cout<<"\n Enter the integers : ";

cin>>a;

if(a!=0){

if (max<a)

max=a;

if (min>a)

min=a;

}

& }

cout<<"max = "<<max<< " \n";

cout<<"min = "<<min<< " \n";

cout<<"max-min= "<<max-min<< " \n\n\n";

system("PAUSE");

}

## Comments

## Leave a comment