someone please help me do the loop .....thanks ...
..here is the problem ...the user will enter integer values until 0 is entered. The program will find the lowest and highest values entered.It will also calculate the total number of value entered.....

#include <iostream>
#include <iomanip>

using std::cout;
using std::cin;
using std::endl;

int main()
{
    int highestInt = 0;
    int lowestInt = 0;
    int integer;
    int counter = 0;
    
cout << "Input integer: " ;
cin >> integer ;

while (integer==0)
 {
   counter ++ ;           
 }

if (integer > highestInt)
   highestInt = integer;
   
if (integer < lowestInt)
   lowestInt=integer;
   
   counter = counter + 1;
   
   cout << "lowest number: " << lowestInt << endl;
   cout << "highest number: "  << highestInt << endl;
   cout << "count number: " << counter << endl;
   
  
system("pause");
return 0;
}

Recommended Answers

All 2 Replies

Trace through your program by hand and see what happens when you enter 0 (hint the while is going to spin forever because integer == 0 will always be true -- which causes the loop to continue not stop).

Also do this for finding the highest and lowest numbers. You'll find you'll need to rearrange your loop to encompass more of your statements. As it stands your code only goes through once if the number is nonzero and gets stuck in an infinite loop if it is zero.

#include <iostream>
#include <iomanip>

//using std::cout;    // istade of using std again and again u can use using namepasce std;
//using std::cin;
//using std::endl;

using namespace std;

int main()
{
    int highestInt = 0;
    int lowestInt = 0;
    int integer=1;    // set a value which is not 0
    int counter = 0;
    
    
while (integer!=0)   
{      
		cout << "Input integer: " ;  //take tha inut inside the while
		cin >> integer ;
		int t=integer;

	


 

if (integer > highestInt)
   highestInt = integer;
   
if (integer < lowestInt)
   lowestInt=integer;
   
   counter = counter + 1;
   
   cout << "lowest number: " << lowestInt << endl;
   cout << "highest number: "  << highestInt << endl;
   cout << "count number: " << counter << endl;
   
}
  
system("pause");
return 0;
}
commented: Don't just give away the code, let the OP work towards it themselves -1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.