473,378 Members | 1,393 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,378 software developers and data experts.

Need ideas on changing to switch structure

I am a beginner. I am supposed to use a switch structure. I wrote
the code below, which works great, but I can't come up with a
reasonable usage of the switch structure for this program. Any ideas
would be appreciated.

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

string isAcceptable(int &est, int &act);

int main ()
int estTime, actTime;

cout << "\n\n What is the estimated flight time? ";
cin >estTime;
cout << "\n\n What is the actual flight time? ";
cin >actTime;
cout << isAcceptable(estTime, actTime) << endl;

string isAcceptable(int &est, int &act)
int margin, diff, x;

//acceptable error margin in minutes table
if (est >= 0 && est <= 29)
margin = 1;
else if (est >= 30 && est <= 59)
margin = 2;
else if (est >= 60 && est <= 89)
margin = 3;
else if (est >= 90 && est <= 119)
margin = 4;
else if (est >= 120 && est <= 179)
margin = 6;
else if (est >= 180 && est <= 239)
margin = 8;
else if (est >= 240 && est <= 359)
margin = 13;
else if (est >= 360)
margin = 17;

// diff between the est & act times
if (est act)
diff = (est - act);
diff = (act - est);

//acceptable differences are less than or equal to the
//margin of error for the estimated time slot
if (diff <= margin)
return "\n\t The flight time is acceptable.";
else{ //excedes the margin of error
if (diff margin)
x = (diff - margin);
x = (margin - diff);

//convert x int to char
std::string s;
std::stringstream out;
out << x;
s = out.str();

return "\n\t The flight delay is not acceptable."
"\n\t The estimate is off by: " + s + " minutes.";
Mar 9 '08 #1
0 1106

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Tom | last post by:
I am looking for some ideas for how to design the layout of the form for data entry and to display the data for the following situation: There are many sales associates. A sales associate can work...
by: John N. | last post by:
Hi All, Here I have a linked list each containing a char and is double linked. Then I have a pointer to an item in that list which is the current insertion point. In this funtion, the user...
by: Nadav | last post by:
Hi, I am using FileStream's Async API: BeginRead/EndRead, upon completion callback execution I use the read data and call EndRead, Taking that in mind, I Wonder... does calling EndRead will cause...
by: moondaddy | last post by:
I have some text in a page that when a certain even happens, I need to make it glow from black to red (through a spand of 1 second) pause for a few seconds, and then slowly change from red to black...
by: Darian | last post by:
I am wondering how (if it is possible of course) I can change a users screen resolution to a certain size when running my application and then change it back when they exit my application. For...
by: CptDondo | last post by:
I've been struggling with this concept for a while, and I'm getting a bit burned out... I've got a piece of equipment that has data that I need to get. The data is stored in "bytes" for lack...
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site...
by: Dale | last post by:
Access 2000 I have a check scanner from Magtek, (MicrImage) This is like a "point of sale" check scanner/credit card reader. Magtek furnished 2 ocx's (MTMicrImage.ocx & SaxComm8.ocx). They also...
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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,...
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
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...
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.