473,581 Members | 2,648 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Switch Operator

8 New Member
ok I have to do the following to a previous program

A) Modify the program loop such that a ‘SWITCH’ structure is used to call each of the FUNCTIONS which display the individual Logical Operator Truth Tables, and
B) Upon terminating the program, display a message as follows:
“Thank you for using the Logical
Operator Truth Table Display Program:
‘Your full name’ “

Here's the program. Need advice on switch structure and how to displat that message
// Asgn4.cpp
// March 4,2008
// 2:35 pm
// Program that uses function to display
// truth tables for the Logical And,
// Logical Or, and Logical Not operators

#include <iostream>
using std::cout; // outputs data
using std::endl; // endline
using std::cin; //inputs data
using std::boolalpha; // causes bool values to print as "true" or "false"
void AND ()
void OR ()
void NOT ()

// program has to display truth table at user's will and loop until user quits
int main()

int a, b; // variables to store user input

do {
cout << "Choose one truth table to display:";
cin >> a; // input for truth table to display
if ( a == 1)
AND ();
// if user chooses 1 display logical and truth table

if ( a == 2)
OR ();
// if user chooses 2 display logical or truth table

if ( a == 3 )
NOT ();
// if user chooses 3 display logical not truth table

// loop until user quits
cout<<"Do you want to quit? Press 1 to quit or 0 to display another truth table \n";
cin>>b; // input answer for continuance
} while ( b!= 1 ); // input of one needed to terminate

return 0; // indicate successful termination

void AND()
// create truth table for && (logical AND) operator
// make function
cout << boolalpha << "Logical AND (&&)"
<< "\nfalse && false: " << ( false && false )
<< "\nfalse && true: " << ( false && true )
<< "\ntrue && false: " << ( true && false )
<< "\ntrue && true: " << ( true && true ) << "\n\n";
void OR ()
// create truth table for || (logical OR) operator
// make function
cout << boolalpha << "Logical OR (||)"
<< "\nfalse || false: " << ( false || false )
<< "\nfalse || true: " << ( false || true )
<< "\ntrue || false: " << ( true || false )
<< "\ntrue || true: " << ( true || true ) << "\n\n";
void NOT ()
// create truth table for ! (logical negation) operator
cout << boolalpha << "Logical NOT (!)"
<< "\n!false: " << ( !false )
<< "\n!true: " << ( !true ) << endl;
cout <<"\n";
Mar 17 '08 #1
1 2387
9,208 Recognized Expert Moderator Expert

Expand|Select|Wrap|Line Numbers
  1. switch(a)
  2. {
  3.     case 1:
  4.         etc...
  5.         break;
  6. }
You can only switch on an integer value.

This should be in any textbook.
Mar 17 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

by: clueless_google | last post by:
hello. i've been beating my head against a wall over this for too long. setting the variables 'z' or 'y' to differing numbers, the following 'if/else' code snippet works fine; however, the 'case' code snippet does not. (the code's function is illustrative.) ////////////////////////////////////////// //////// working 'if/else' switch...
by: Tom Morgan | last post by:
Hi everyone, I'm having a brain freeze today so if the answer is a misplacced comma or a missing command, I would be happy. What I want to do is use access to return results via an .asp page. <coff> is the table <postion> is the column I do not want the results in alpha order, but the order specified below, but I keep getting a syntax...
by: webzila | last post by:
Hello, I have to write a program for an 8051 micro-controller using micro-C to monitor Switch 1 and if the switch in pushed the message "switch 1 pushed" should be displayed in the LCD. Also the microcontroller should display in the LCD the value of the voltage applied to the input of the ADC. The above procedure should only execute once...
by: Tim Cowan | last post by:
Hi I was wondering if someone could help me change these ifs to a switch statement. I tried but I can't make it work. Thanks Tim Code below: protected void SetThisControl(System.Web.UI.Control WebControl1)
by: Yuriy Solodkyy | last post by:
Hi VS 2005 beta 2 successfully compiles the following: using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program {
by: nobody | last post by:
With Visual C++ 2005 beta 2, I get the below compling error for the following code. I think this error is not acceptable to me because int::typeid is a constant and is known to compiler when compiling. Will VC++ 2005 implement switch with case int::typeid in the final release? error C2450: switch expression of type 'System::Type ^' is...
by: Raj | last post by:
public static void HandleException(ref Exception io_exException, bool i_blnPropagateException) { switch (true) { case io_exException is ApplicationHandledException: { if (i_blnPropagateException) {
by: babysweet | last post by:
hi..i had problem in my coding..can u fix for me??urgently.. #include<iostream> #include<string> using namespace std; int main() { string movie_name; int ticket_price; double adult_ticket_price;
by: Miyagi | last post by:
I have a bunch of conditions in which to determine different types of questions to ask in a survey I am constructing. Just was wondering if anybody has used a two-dimensional switch statement. If this works, is this an efficient coding method or would anybody else have another way around this? $type = enters _POST as (employee, client, or...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.