Validation problem

Hello. I'm having trouble about the validation code. I created the Fundraiser program and I want to ask a question if there's a customer by asking Yes or No. I press "y" and it shows the print result without going to the next question. The "n" part is correct except the "y." Here's the full 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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#include <iostream>
#include <iomanip>
using namespace std;

#define STARBUCKS 1.00           /* Starbucks */
#define CHIPOTLE 1.50            /* Chipotle */
#define DOSCOYOTES 2.00          /* Dos Coyotes */
#define SIZE 50					 /* The size of arrays - limit to 50 people or less */

int main()
{
   int     totalamount,         /* total amount of all gift cards */
	       ID_Number,           /* Student ID number */
		   numcards,            /* original price */
		   scardsold=0,         /* number of Starbucks cards sold */
		   ccardsold=0,         /* number of Chipotle cards sold */
		   k, i=0,            /* counters */
		   howmany,
		   num=0,                 // number setup (if optional purposes)
		   dosccardsold=0;      /* number of Dos Coyotes cards sold */
   char    yesno,                      /* loop controller, loops when = y or Y */
           cards;                      /* cards used for switch method */
   double  studentprofit [SIZE],       /* array of student profit */
	       largestfund=0,         /* largest funds */
		   smallestfund=0,        /* smallest funds */
		   averagefund=0,         /* average funds */
		   sum=0,
		   sbprofit=0,          /* sub total 1 for Starbucks*/
		   chipprofit=0,        /* sub total 2 for Chipotle*/
		   doscprofit=0,        /* sub total 3 for Dos Coyotes*/ 
           totalrevenue;        /* total amount of revenue */
		   

   cout << "\nWilliam Lam's Fundraiser Program";
   cout << "\n\n";

   /* While Loop area */

   cout << "\nDo you have a student sale to enter? (Y = Yes, N = No)   ";
   cin  >> yesno;

   //validation
  
   while (yesno != 'Y' && yesno != 'y' && yesno != 'N' && yesno != 'n')
   {
	   cout << "\n Sorry, that was not the right letter.";
	   cout << "\n Do you have a student sale to enter (Y = Yes, N = No)  ";
	   cin >> yesno;

	   /* Switch area */
	  
		cout << "\nPlease enter the student ID number: ";
		cin  >> ID_Number;
		while (ID_Number < 10000 || ID_Number > 99999)
		{
			cout << "\nInvalid Student ID number. Please enter your ID Number again: ";
			cin >> ID_Number;
		}
		cout << "\nPlease enter the type of card sold (S for Starbucks, C for Chipotle, and D for Dos Coyotes): ";
		cin  >> cards;
		while (!(cards == 's' || cards == 'S' || cards == 'c' || cards == 'C' || cards == 'd' || cards == 'D'))
		{
			cout << "\nInvalid card type. Please enter the type of card (S for Starbucks, C for Chipotle, and D for Dos Coyotes): ";
			cin >> cards;
		}
		cout << "\nPlease enter the quantity of the type of girft cards: ";
		cin  >> numcards;
		while (numcards <= 0)
		{
			cout << "\nInvalid the number of cards. Please enter the limit amount of gift cards ";
			cin >> numcards;
		}

	   switch(cards)
	   {
		  case 'S':
		  case 's':
			 studentprofit[i] = numcards * STARBUCKS;
			 sbprofit += studentprofit[i];
			 scardsold += numcards;
			 cout << "\n\n";
			 cout << "\nStudent " << ID_Number << " raised the following amount for the school $" << studentprofit[i] << " .\n";
			 cout << "\n\n";
			 break;
		  case 'C':
		  case 'c':
			 studentprofit[i] = numcards * CHIPOTLE;
			 chipprofit += studentprofit[i];
			 ccardsold += numcards;
			 cout << "\n\n";
			 cout << "\nStudent " << ID_Number << " raised the following amount for the school $" << studentprofit[i] << " .\n";
			 cout << "\n\n";
			 break;
		  case 'D':
		  case 'd':
			 studentprofit[i] = numcards * DOSCOYOTES;
			 doscprofit += studentprofit[i];
			 dosccardsold += numcards;
			 cout << "\n\n";
			 cout << "\nStudent " << ID_Number << " raised the following amount for the school $" << studentprofit[i] << " .\n";
			 cout << "\n\n";
			 break;
		  default:
			 cout << "\nAn invalid number was entered.\n";
	   } 
	   //end case

	   cout << "\nDo you have a student sale to enter? (Y = Yes, N = No)   ";
	   cin  >> yesno;
	  
		while (yesno != 'Y' && yesno != 'y' && yesno != 'N' && yesno != 'n')
		{
			cout << "\n Sorry, that was not the right letter.";
			cout << "\n Do you have a student sale to enter (Y = Yes, N = No)  ";
			cin >> yesno;
	   }
	   //validate
	   i++;

	   if ( i >= SIZE)
		   yesno = 'n';
   } 
   //End While Loop

   totalamount = scardsold + ccardsold + dosccardsold;
   totalrevenue = sbprofit + chipprofit + doscprofit;

   /* Results in Print Receipt */

   cout << "\n\n\n\n       William Lam's Fundraiser Receipt";
   cout << "\n--------------------------------------------------";
   cout << "\nTotal number of Starbucks gift cards sold:         $ " << setw(7) << scardsold << "\n"; 
   cout << "\nTotal number of Chipotle gift cards sold:          $ " << setw(7) << ccardsold << "\n";
   cout << "\nTotal number of Dos Coyotes gift cards sold:       $ " << setw(7) << dosccardsold << "\n";
   cout << "\nTotal number of all gift cards sold                $ " << setw(7) << totalamount << "\n";
   cout << "\n--------------------------------------------------";
   cout << "\nTotal revenue from Starbucks gift cards:           $ " << setw(7) << sbprofit << "\n";
   cout << "\nTotal revenue from Chipotle gift cards:            $ " << setw(7) << chipprofit << "\n";
   cout << "\nTotal revenue from Dos Coyotes gift cards:         $ " << setw(7) << doscprofit << "\n";
   cout << "\n--------------------------------------------------";
   cout << "\nTotal revenue raised:                              $ " << setw(7) << totalrevenue << "\n";
   cout << "\n";
   
   
   howmany = i;
   
   smallestfund = studentprofit[0];
   largestfund = studentprofit [0];
   averagefund = studentprofit [0];
   for (i = 0; i < howmany; i++)
   {
	   if (smallestfund > studentprofit[i])
		   smallestfund = studentprofit[i];
	   else if (largestfund < studentprofit[i])
		   largestfund = studentprofit[i];
	   cout << "\n\n\n" << setw(9) << studentprofit[i];
   }

   for (i = 0; i < howmany; ++i)
   {
	   sum += studentprofit[i];
	   averagefund = sum/howmany;
   }
   if (howmany > 0)
   {
   //Total Funds Raised Array
   cout << "\n--------------------------------------------------";
   cout << "\nThe largest amount of funds raised:         $ " << fixed << setprecision(2) << setw(21) << largestfund;
   cout << "\nThe smallest amount of funds raised:        $ " << fixed << setprecision(2) << setw(22) << smallestfund;
   cout << "\nThe average amount of funds raised:         $ " << fixed << setprecision(2) << setw(27) << averagefund;
   cout << "\n--------------------------------------------------";
   cout << "\n";
   cout << "\nThank You For Shooping! Enjoy your day!";
   cout << "\n";
   }
   else if (howmany <= 0)
   {
	   cout << "\nThe largest amount of funds raised:         $ ";
	   cout << "\nThe smallest amount of funds raised:        $ ";
	   cout << "\nThe average amount of funds raised:         $ ";
	   cout << "\n--------------------------------------------------";
	   cout << "\n";
	   cout << "\nThank You For Shooping! Enjoy your day!";
       cout << "\n";
   }

   return 0;
   }


Can you give the right results on how to fix this solution?
your while statement says that if yesno is not Y and not y and not N and not n, meaning if you input any of those for the first question, it will skip the loop. You can see this by entering in a letter outside of those parameters and then it will take you into the loop. Try it out.
Topic archived. No new replies allowed.