C++ is broken?? JK, but help please?

Hello all,

Thanks for looking over my code below. I've been having some problems after line 83. Anything cin entry that should wait for the user to enter information isn't and is skipped, then printing the rest of the code to the screen. Could someone please point out any errors that may be happening. Thank you so much!
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
1 // Sam Vernaza
  2 // Purpose of this program is to practice basic construction of a C++ Program
  3 
  4 #include <iostream>
  5 #include <cctype>
  6 
  7 using namespace std;
  8 
  9 int main()
 10 {
 11     // initializing statements
 12   char initials;
 13   char initials_2;
 14   char initials_3;
 15   char result1;
 16   char result2;
 17   char result3;
 18   float wage = 00;
 19   float hours = 00;
 20   int response;
 21   char redo;
 22 // outer do while for repeat of entire body of code
 23  do
 24   {
 25       cout << "\t\t***Welcome Employee!***" << endl;
 26     do
 27      {
 28        cout << " Enter each of your initials followed by an enter after each character (Alphabetical Characters ONLY)" << endl;
 29        cin >> initials;
 30        cin.ignore(10,'\n');
 31        result1 = toupper(initials);
 32 
 33        cin >> initials_2;
 34        cin.ignore(10,'\n');
 35        result2 = toupper(initials_2);
 36 
 37        cin >> initials_3;
 38        cin.ignore(10,'\n');
 39        result3 = toupper(initials_3);
 40 
 41 
 42        cout << "You entered: " << result1 << result2 << result3 << endl;
 43      } while (!isalpha(initials) && !isalpha(initials_2) && !isalpha(initials_3));
 44 
 45 // initializing statement for next do while loop   
 46     char check;
 47   do
 48    {
 49        cout << "What is your hourly wage? (Enter a positive value)" << endl;
 50        cin >> wage;
 51        cin.ignore ( 100, '\n' );
 52 
 53        cout << "How many hours have you worked? (Enter a positive value)" << endl;
 54        cin >> hours;
 55        cin.ignore (100, '\n');
 56 
 57        if (wage > 0)
 58           cout << "You've worked: " << hours << " hours and your wage is : " << wage << endl;
 59        else
 60           cout << "Invalid Entry" << endl;
 61      } while (wage < 0);
 62 
 63    do
 64     {
 65        cout << "Is there a cost of living increase? (Y/N)" << endl;
 66        cin >> response;
 67        cin.ignore (100,'\n');
 68        response = toupper(response);
 69 
 70        if (response == 'Y')
 71          {
 72            float pay_I = hours * (wage * 1.5);
 73            cout << "Your pay is: $ " << pay_I << endl;
 74          }
 75        else
 76          {
 77            float pay = hours * wage;
 78            cout << "Your pay is: $ " << pay << endl;
 79          }
 80  // printing to screen, not allowing any user entry from line 83 down      
 81       char check;
 82       cout << "Is this information correct? (Y/N)" << endl;
 83       cin >> check;
 84       cin.ignore (100,'\n');
 85       check = toupper(check);
 86    } while (check == 'Y');
 87 
 88   char redo;
 89   cout << "Would you like to enter another employee's wage and hours? (Y/N)\n ";
 90   cin >> redo;
 91   cin.ignore (100,'\n');
 92   redo = toupper(redo);
 93 
 94    if (redo == 'Y' || redo == 'y')
 95       cout << "\n\nNext employee please enter your information below.\n\n" << endl;
 96    else
 97       cout << "\nGoodbye\n" << endl;
 98   } while (redo == 'Y' || redo == 'y');
 99 
100 
101  return 0;
102 }

Why are you using cin.ignore so much?

Also, you have two variables called redo and two variables called check.

Line 86 should be while ( check == 'N' );
Last edited on
Hey,

I'm just doing what my teacher told me to do. I'm clearing the input buffer.

Thanks for the catch. I will test that out.
Topic archived. No new replies allowed.