Answer to Question #300679 in C for Nobody

Question #300679

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.


1
Expert's answer
2022-02-22T16:31:58-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS