Understanding BOOL for a FOOL

closed account (91AfSL3A)
I need to create a loop to return a minimum value using a boolean variable but don't quite understand how to format my algorithm.

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

using namespace std;

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;
}



I know its jacked up any comments in the code would be great I need to finish the program but also understand it. Thanks.
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
#include <iostream>

using namespace std;

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
- I think your algorithm is jacked up as you say because you don't seem to know what you're doing, and i'm not sure what you're trying to do either.

- More information about your assignment would help.
closed account (91AfSL3A)
Thanks yeah I just keep getting myself more confused but the prompt is too ask the user to input number(s) and then to return the minimum value of those numbers which can be positive or negative. The specifics of the program are use any loop and boolean variable types.
- Then i suggest you set up either a switch statement or if else statements and use a menu instead of having the user enter "x" to quit.

- After that, just use the loops and do what you need to do.

- Moreover, using boolean variables in this example seems somewhat pointless unless your professor is building up to something that i'm not seeing.

- Additionally, i don't see you returning 0 in your code, and i would advise you to make a menu and make a do while loop so that the user can do what he/she wants to until he/she wants to quit.
From what I'm reading, you need to write a program that accepts a input of number(s) and then tell the user what the lowest number they inputted?

So: 2, 7, 12.

Lowest will be 2?

If so; I would suggest using an arrary or vector to place the inputs into and then check for the lowest and output it.
I would use /you don't know how many elements user is going to put/

int*p = new int[n];
//..........

delete [] p;

Last edited on
Topic archived. No new replies allowed.