loops with bool

closed account (91AfSL3A)
#include <iostream>

using namespace std;

Having some issues with this program needs to use a loop an bool variables
Output should look like this
Enter a number (X to Exit): -11
Enter a number (X to Exit): x

Minimum value: -11

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 #include<iostream>

int main() {

    bool first = true;
    while (first) {
		cout << "Enter a number (X to exit): ";
		int num;
		cin >> num;
	if(first){
	min = value;
	first = false;
	} else if (value < min){
	min = value;
    }cout << "Minimum value: " << min << endl;
    }
    return false;
}
Last edited on
Without testing...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>

int main()
{
   bool first = true;
   int min;

   while ( true )
   {
      std::cout << "Enter a number (X to exit): ";

      int number;
      if ( !( std::cin >> number ) ) break;

      if ( first )
      {
         min = number;
         first = !first;
      }
      else if ( number < min )
      {
         min = number;
      }
   }

   if ( !first ) std::cout << "The minimum = " << min << std::endl;
   else std::cout << "You did not enter any number" << std::endl;

   return 0;
}
Last edited on
Topic archived. No new replies allowed.