Code Help!!!

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()
    {
          int n;
          int abort;
          cout << "Input the number you would like to start the countdown from" << endl;
          cout << "press Enter, then input your abort number!!!" << endl;
          cin >> n >> abort;
          If (abort>n)
          {
                cout << "ERROR!!! Make countdown > abort\n Reenter now... \n";
                cin >> n >> abort;
                }
         Do
          {
                cout << n << endl;
                If (n == abort)
                   cout << "ABORTED!!!"}
                   }While (n>0)}

What is the matter with this, I want the user to decide when to abort the countdown, please help :)
closed account (z05DSL3A)
This should get you closer to where you want to be:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<iostream>
using namespace std;

int main()
{
    int n;
    int abort;
    cout << "Input the number you would like to start the countdown from" << endl;
    cout << "press Enter, then input your abort number!!!" << endl;
    cin >> n >> abort;
    if (abort>n)
    {
        cout << "ERROR!!! Make countdown > abort\n Reenter now... \n";
        cin >> n >> abort;
    }

    do
    {
        cout << n << endl;
        if (n == abort)
            cout << "ABORTED!!!"}
        --n;
    }while (n>0);
}
Thx much dude but it didnt work lol... it just printed aborted before everything :P
Easy fix, you almost had it correct. Comments where I changed the code.
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
#include<iostream>
using namespace std;

int main()
{
    int n;
    int abort;
    cout << "Input the number you would like to start the countdown from" << endl;
    cout << "press Enter, then input your abort number!!!" << endl;
    cin >> n >> abort;

    if (abort>n)
    {
		do     // added do... while loop to get correct data
		{
			cout << "ERROR!!! Make countdown > abort\n Reenter now... \n";
			cin >> n >> abort;
		}while (abort > n);
    }

    while (n >= abort)     //  changed code here
    {
        cout << n << endl;
        if (n == abort)
            cout << "ABORTED!!!" << endl;   // added line break here
        --n;
    }

	return 0;
}
Topic archived. No new replies allowed.