Reducing numbers to 0
Feb 18, 2013 at 5:14am UTC
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;
}
Feb 18, 2013 at 5:20am UTC
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 Feb 19, 2013 at 2:04pm UTC
Feb 18, 2013 at 1:24pm UTC
First off, these do the same thing.
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 Feb 18, 2013 at 1:25pm UTC
Topic archived. No new replies allowed.