473,394 Members | 1,794 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,394 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);
else
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);
else
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 1108

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

Similar topics

10
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...
5
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...
5
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...
3
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...
6
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...
1
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...
20
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...
0
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...
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: 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?
1
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...
0
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,...
0
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,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.