473,795 Members | 2,865 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
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 2396
weaknessforcats
9,208 Recognized Expert Moderator Expert
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
9589
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 //////// //////////////////////////////////////////
2
5059
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 error: 'Syntax error (missing operator) in query expression '
13
6220
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 the user has entered "1234" using a keypad that is attached to the 8051 microprocessor.
7
5521
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)
27
5639
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
3118
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 illegal 1> No user-defined-conversion operator available, or 1> Integral expression required
9
1611
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) {
1
1935
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;
2
1853
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 peer) $visit = enters _POST as ( 0 or 1 ) $userage = enters _POST as ( 1, 2, 3, or 4) $ip is the...
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10436
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10000
tracyyun
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9040
agi2029
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3722
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.