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

Online lab help please.

64
Hello, I been working at this for about 30 minutes now and can't seem to get it. This part is called One-Way selection. Here is the question...

Given the integer variables x , y , and z , write a fragment of code that assigns the smallest of x , y , and z to another integer variable min .

Assume that all the variables have already been declared and that x , y , and z have been assigned values).
Here is the code the provide

Expand|Select|Wrap|Line Numbers
  1. 1 int main() {
  2. 2    int x, y, z, min;
  3.  
Your Code here...

Expand|Select|Wrap|Line Numbers
  1. 6    return 0;
  2. 7 }
  3.  

Now my question is how wold you find which one has the lowest amount?
Feb 20 '07 #1
8 1730
sicarie
4,677 Expert Mod 4TB
Hello, I been working at this for about 30 minutes now and can't seem to get it. This part is called One-Way selection. Here is the question...



Here is the code the provide

Expand|Select|Wrap|Line Numbers
  1. 1 int main() {
  2. 2    int x, y, z, min;
  3.  
Your Code here...

Expand|Select|Wrap|Line Numbers
  1. 6    return 0;
  2. 7 }
  3.  

Now my question is how wold you find which one has the lowest amount?
How would you find the lowest amount? Without a computer program?
Feb 20 '07 #2
td0g03
64
How would you find the lowest amount? Without a computer program?
I would first look at all the numbers and see which one is the lowest. Or I would do if A<B and A<C then A is the lowest. If not then etc etc.
Feb 20 '07 #3
sicarie
4,677 Expert Mod 4TB
I would first look at all the numbers and see which one is the lowest. Or I would do if A<B and A<C then A is the lowest. If not then etc etc.
So you would compare one to the other, store the smaller of the two, compare it to the next, and keep doing that until you have completed the program.

You have your algorithm right there, where are you stuck? On the comparisons?
Feb 20 '07 #4
td0g03
64
So you would compare one to the other, store the smaller of the two, compare it to the next, and keep doing that until you have completed the program.

You have your algorithm right there, where are you stuck? On the comparisons?
Well, when I try this

Expand|Select|Wrap|Line Numbers
  1. if (x<y && x<z)
  2.     min= x;
  3. else
  4. if (y<x && y<z)
  5.     min= y;
  6. else
  7. if (z<x && z<y)
  8.     min= z;
  9.  
I get the error
Suggestion: You are not assigning anything to min.
Feb 20 '07 #5
sicarie
4,677 Expert Mod 4TB
Well, when I try this

Expand|Select|Wrap|Line Numbers
  1. if (x<y && x<z)
  2.     min= x;
  3. else
  4. if (y<x && y<z)
  5.     min= y;
  6. else
  7. if (z<x && z<y)
  8.     min= z;
  9.  
I get the error
I would try removing the else statements, see what that does.
Feb 20 '07 #6
td0g03
64
I would try removing the else statements, see what that does.
No luck darn.
Feb 20 '07 #7
sicarie
4,677 Expert Mod 4TB
No luck darn.
If that didn't work, I would try each one by itself.
Feb 20 '07 #8
nmadct
83 Expert
It looks fine, with the else statements. The problem is that the compiler can't tell that in all cases one of the three must be true, so it thinks that in some cases, min might be unassigned. Make it shut up by declaring min=0 at the top of your program. That way, it's satisfied because min will always be defined.
Feb 20 '07 #9

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

Similar topics

3
by: Leszek | last post by:
Hi everybody, I need your help-I want to display all users which are online on my web page and I don't know how to do this. I know how to do this whit one IP but for more - I don't. HELP ME...
2
by: Mario | last post by:
Hi, I'm experiencing a nasty problem with Visual Studio .Net 2003. Most Online Resources in the Start Page doesnt work, showing the following message: "This feature requires that you have...
1
by: Cameron | last post by:
Suddenly, none of my online data entry forms work anymore. On several sites, where once I had perfectly- working forms for the online admin of web page content (via Access database), now, when I...
24
by: jason | last post by:
Hi Ray...a while ago you explained an elegant solution to enable me to CREATE and EDIT existing tables and queries inside my online access 2000 database.... could you provide refresher links on...
21
by: Paulb1us | last post by:
In VS .net 2003 There is a online resources tab on the start page. When I click the links such as headlines, downloads or xml services I get a message stating that this feature requires a...
0
by: Lior Bobrov | last post by:
Hello . I now have Visual Studio 2005 Common Technology Preview (CTP) February 2005 with no MSDN . I try to use the MSDN Online from within the IDE , as follows : In the IDE , I click...
0
by: Technical Resercher | last post by:
My agency is organizing an online forum group. Our purpose is to gather information from consumers, like you, on dedicated servers. We want to gain knowledge about the industry, the dedicated...
3
by: Konstantin Andreev | last post by:
Hello, everybody. I've spent a lot of time reading "DB2 Information Center" and Raul Chong's book "Understanding DB2. Learning Visually with Examples", but still unable to answer this simple...
10
by: Konstantin Andreev | last post by:
Hello. Some time ago I asked in this conference, - How to use an ONLINE BACKUP to restore database onto another system? - but got no answers. Therefore I can conclude it is not possible. But......
14
by: freefony | last post by:
please help me with this <?php $sc=$_POST; $name=$_POST; $emp=$_POST; include("conn.php"); $qry="select employer from corper"; $rst=mysql_query($qry) or die(mysql_error()); <select...
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
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
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...
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
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
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
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...
0
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...
0
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,...

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.