Countdown...

I Got My Code Up And Running The Way I Want, Only Thing I Want To Know Is How Do I Make The Counter Count TO The Number Imputed Instead Of Counting FROM The Number??? Basically I Want A Countup Not A Countdown. Here Is My Code


#include <iostream>
using namespace std;
int main ()
{
 int n,mod_test;

 cout << "Enter the ending number > ";
 cin >> n;
 cout << "\n";
 while (n>0) 
 { 
      {
        mod_test = n%10;        
        if (mod_test==0 || n==11 || n==12 || n==13) 
        {
    cout << n << "th hello \n ";
         }
    else if (mod_test==2)
    {
    cout << n << "nd hello \n ";
    }
    else if(mod_test==1)
    {
    cout << n << "st hello \n ";
    }
    else if (mod_test==3)
    {
    cout << n << "rd hello \n ";
    }
    else
    {
    cout << n << "th hello \n ";
    }
    n--;
  }    
 }
 system("pause"); 
 return 0;
}

@Memo Gonzalez

Your mod_test check didn't work as you wanted. Here is how I corrected it.

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
// Count Up.cpp : main project file.

#include <iostream>

using namespace std;
int main ()
{
 int n=0,mod_test, x=1; // x is used to check when n is reached

 cout << "Enter the ending number > ";
 cin >> n;

 cout << "\n ";
do
 { 
     mod_test = x%10;

	if (x<10)
		cout << " "; // Add a space when x < 10 just to keep text aligned on screen
	if (x<100)
		cout << " "; // Add another space while x < 100 just to keep the text aligned
	if ((mod_test >= 4 && mod_test <= 9) || mod_test==0 || (x>=4&&x<=20))
	{
		cout << x << "th hello \n ";
	}
	else if (mod_test==3)
    {
		cout << x << "rd hello \n ";
	}
    else if(mod_test==2)
    {
		cout << x << "nd hello \n ";
	}
    else if (mod_test==1)
    {
		cout << x << "st hello \n ";
	}
    x++;    
 }while (x!=n+1);
 system("pause"); 
 return 0;
}
Last edited on
Topic archived. No new replies allowed.