Question

In: Computer Science

Write a program that prints the question “Do you wish to continue?” and reads the input....

Write a program that prints the question “Do you wish to continue?” and reads the input. If the user input is “Y”, “Yes”, “YES”, then print out “Continuing”. If the user input is “N” or “No”, “NO” then print out “Quit”. Otherwise, print “Bad Input”. Use logical operators. c++

Solutions

Expert Solution

/* There are following logical operators supported by C++ language.

1. && :- Called Logical AND operator. If both the operands are non-zero, then condition becomes true.
example. (A && B) is false.

2. || :- Called Logical OR Operator. If any of the two operands is non-zero, then condition becomes true.
example. (A || B) is true.

3. ! :- Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true, then Logical NOT operator will make false.
example. !(A && B) is true.
*/

// C++ program to illustrate logical operater while taking input from user

#include <iostream>
#include<string.h> // For string compare
using namespace std;

int main()
{
   // Because we have yes as maximum length so charater array of 3 element declared
char input[3];
  
   // Ask question to user for an input
cout << "Do you wish to continue? ";
cin >> input;
  
   /* Here we are using strcmp function in string.h for cpmparing input with our given criateria
       and logical or operator if any 1 condition is true then it gives output else gives error*/
      
   // This if checks for yes condition  
if( strcmp(input, "Y")==0 || strcmp(input, "Yes")==0 || strcmp(input, "YES")==0 )
cout << "\ncontinuing";
       // This if condition check for no condition  
else if( strcmp(input, "N")==0 || strcmp(input, "No")==0 || strcmp(input, "NO")==0)
cout << "\nQuit";
       // otherwise it comes here  
else
cout << "\nBad Input";
  
return 0;
}

/* output :-

1) Do you wish to continue? NO

Quit

2) Do you wish to continue? Y

continuing

3) Do you wish to continue? kjhgjh

Bad Input

*/


Related Solutions

Write a short main program that reads an integer n from standard input and prints (to...
Write a short main program that reads an integer n from standard input and prints (to standard output) n lines of * characters. The number of *’s per line should double each time, starting with 1. E.g., if n = 5, the output should be as follows: * ** **** ******** ****************
Write a program called x.c that reads an integer n from standard input, and prints an...
Write a program called x.c that reads an integer n from standard input, and prints an nxn pattern of asterisks and dashes in the shape of an "X". You can assume n is odd and >= 5. Solve this problem using only while loop. Solution: ./x Enter size: 5 *---* -*-*- --*-- -*-*- *---* ./x Enter size: 9 *-------* -*-----*- --*---*-- ---*-*--- ----*---- ---*-*--- --*---*-- -*-----*- *-------* ./x Enter size: 15 *-------------* -*-----------*- --*---------*-- ---*-------*--- ----*-----*---- -----*---*----- ------*-*------ -------*------- ------*-*------...
Write a program called distance_square.c that reads an integer n from standard input, and prints an...
Write a program called distance_square.c that reads an integer n from standard input, and prints an nxn pattern of integers. Each integer is the minimum number of steps required to reach the centre of the square. Steps can only be up, down, left or right (no diagonal movement). the question should be allowed to use only while loop 4 3 2 3 4 3 2 1 2 3 2 1 0 1 2 3 2 1 2 3 4 3...
Write a Python program that reads in an amount in cents and prints the dollar amount...
Write a Python program that reads in an amount in cents and prints the dollar amount in that and the remaining value in cents. For example, if the amount reads in is 360 (cents), the program would print 3 dollars and 60 cents. if the amount read in is 75 (cents), the program would print 0 dollars and 75 cents.
in.java Write a program that reads an integer from the user and prints a rectangle of...
in.java Write a program that reads an integer from the user and prints a rectangle of starts of width 5 3 and height N. Sample run 1: Enter N: 5 *** *** *** *** *** Bye Sample run 2: Enter N: 8 *** *** *** *** *** *** *** *** Bye Sample run 3: Enter N: 2 *** *** Bye Sample run 4: Enter N: -2 Bye
Write a Fortran program that reads in two NxN matrices A & B, and prints their...
Write a Fortran program that reads in two NxN matrices A & B, and prints their element-wise sum (A+B), element-wise difference (A-B), element-wise division (A/B), element-wise product (A*B), and their matrix product (matmul(A,B)), on the standard output.
C program, please Write a program that reads a sequence of 10 integer inputs and prints...
C program, please Write a program that reads a sequence of 10 integer inputs and prints the smallest and largest of the inputs and the number of even and odd inputs. for a beginner please, you could use a while loop,if-else,
*Java program* Use while loop 1.) Write a program that reads an integer, and then prints...
*Java program* Use while loop 1.) Write a program that reads an integer, and then prints the sum of the even and odd integers. 2.) Write program to calculate the sum of the following series where in is input by user. (1/1 + 1/2 + 1/3 +..... 1/n)
Write a pyhton program that reads a stream of bits, e.g. 11001, and calculates and prints...
Write a pyhton program that reads a stream of bits, e.g. 11001, and calculates and prints the decimal value of the binary number represented by the entered bits, i.e. 25 in this case.
Write a c program that reads a .img file by rows and columns and prints out...
Write a c program that reads a .img file by rows and columns and prints out the arrays. The .img file contains h(the height) and w(the width) of the text size. An example .img file would be: 2 4 DFJSK HJ5JF HFDY5
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT