Program closes..

Hey im new to these forums && know little about C++ i made this program that uses enum and it decides what to write But the problem is as soon as i type a number in, the program closes i've tried SYSTEM("PAUSE");, the pause>nul etc get cin() or what ever it is. Heres the code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream.h>

int main()
{
    enum Days { Monday = 1, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday };
    
    Days DayOff;
    int x;
        
    cout << "What day would you like off? (1 - 7) : ";
    cin >> x;
    DayOff = Days(x);
    
    if (DayOff == Saturday || DayOff == Sunday)
       cout << "Your already off on weekends..\n";
    else
        cout << "Have a nice holday! Your allowed off";
    
    system("PAUSE");
    
    return 0;
}


Can someone please help i would love for this to work, i know its very simple but it would be nice for it to work :)
hi i'm moetaz from egypt
are you studying from sam's 21 days?
any way to pause the screen i use the order getch();
including <conio.h>
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
# include <iostream.h>
# include <conio.h>

int main()
{
    enum Days { Monday = 1, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday };

    Days DayOff;
    int x;

    cout << "What day would you like off? (1 - 7) : ";
    cin >> x;
    DayOff = Days(x);

    if (DayOff == Saturday || DayOff == Sunday)
       cout << "Your already off on weekends..\n";
    else
        cout << "Have a nice holday! Your allowed off";
     getch();


    return 0;
}


there is another way
not to pause the screen but repeat the program using some loops and sellection statements:
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
# include <iostream.h>
int main()
{
  char test = 'y';     // carries yes or no
  while (test == 'y')
  {
    enum Days { Monday = 1, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday };

    Days DayOff;
    int x;

    cout << "\nWhat day would you like off? (1 - 7) : \n";
    cin >> x;
    DayOff = Days(x);

    if (DayOff == Saturday || DayOff == Sunday)
       cout << "Your already off on weekends..\n";
    else
        cout << "Have a nice holday! Your allowed off\n";
    cout << "do you want to restart !!?\n";
    while (1)           // error check loop
    {
      cin >> test;
      if (test != 'y' && test != 'n')
      {
       cout << "\n wrong answer";
       cout << " put 'y' or 'n':";
      }
      else
      break;
    }
   }


    return 0;
}


i need comments
you are wellcome
i usually use the debugger to find logical or memory bugs like this.

or you'd probably like to insert pauses inbetween the code, instead of just at the end. and enable some cout like after Dayoff = Day(x);, insert a line like cout >> "break1" >> endl; den system pause. coz (juz a reminder that) the code runs top down...
Last edited on
Topic archived. No new replies allowed.