how to make the count start at zero and not go under

how do i automatically assign count to be 0, and to make it not able to go under

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <iostream>
#include <math.h>

using namespace std;

class counterType{
public:
	counterType();
	int counterPlus();
	int counterMinus();
	int counterSet(int set_value);
	int count;
	int countAssign;

};
counterType mycount;

counterType::counterType(){
	int count=0;
};



int counterType::counterPlus(void){
	count++;
	return count;
};

int counterType::counterMinus(void){
	count--;
	return count;
};



int counterType::counterSet (int set_value)
{
   count = set_value;
   return count;
}



int main(){
	int set_value;
	counterType mycount;
	int opselect;
	int startover;
	int count=0;
	while(mycount.count>=0);
	do{

	std::cout<<"please choose from the following options:"<<endl
	<<"1. assign a value to count"<<endl
	<<"2. add '1' to count"<<endl
	<<"3. subtract '1' from count"<<endl;
	cin>>opselect;
	switch(opselect){
	case 1:{
		cout << "Please enter a value to set the count to: ";
cin >> set_value;
mycount.counterSet(set_value);

		   break; };

	case 2:{

		mycount.counterPlus();

		break;};

	case 3:{
		mycount.counterMinus();

		   break;};
	};
	std::cout<<"count is currently:"<<mycount.count<<endl;
	std::cout<<"please enter '0' to start over"<<endl;
	std::cin>>startover;
	}while(startover==0);
	
	

};
a simple:

1
2
if( count < 0 )
    count = 0;


would do it.
Topic archived. No new replies allowed.