Reducing numbers to 0

I am trying to count down a number.. using loops and functions.. but I seem to be having issues..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

int decreaseNumber(int x) {
	
	while(x <= 0) {
		cout << x <<
		x = x - 1;
	}
}

int main() {

	decreaseNumber(5);

	return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void decreaseNumber(int x) {
	
	while(x > 0) {
		cout << x << " ";
		x--; //To decrease your x value
	}
}

int main() {

	decreaseNumber(5);

	return 0;
}



do you get it?
Last edited on
First off, these do the same thing.
1
2
x--;
x = x - 1;


You had you're while-loop wrong, bondman.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
void decreaseNumber(int x) { // You don't return anything, make it void?
	
	while(x >= 0) { // While it's greater/equal to 0, cout/decrement.
		cout << x << ' ';
		x = x - 1;
	}
}

int main() {

	decreaseNumber(5);

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