Create a program based on the sample output using while loop.
--Choices--
E or e for Even
O or o for Odd
X or x for Exit
Enter your choice : X
Your Program will now exit.
#include <stdio.h>
#include <stdlib.h>
int main() {
int flag = 1;
while (flag) {
char c;
scanf("%c", &c);
int r = rand();
if (c == 'e' || c == 'E') {
cout << (r % 2 ? r + 1 : r) << endl;
} else if (c == 'o' || c == 'O') {
cout << (r % 2 ? r : r + 1) << endl;
} else if (c == 'x' || c == 'X') {
flag = 1;
}
return 0;
}
Comments
Leave a comment