473,386 Members | 1,668 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Switch Operator

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
cout<<endl;
} 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 2374
weaknessforcats
9,208 Expert Mod 8TB
Just:

Expand|Select|Wrap|Line Numbers
  1. switch(a)
  2. {
  3.     case 1:
  4.         etc...
  5.         break;
  6. }
  7.  
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

10
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 ...
2
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. ...
13
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...
7
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...
27
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 {
5
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...
9
by: Raj | last post by:
public static void HandleException(ref Exception io_exException, bool i_blnPropagateException) { switch (true) { case io_exException is ApplicationHandledException: { if...
1
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...
2
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
jinu1996
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...

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.