473,668 Members | 2,482 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Check for min and max value in a for loop

1 New Member
I am writing a program that asks for two sets of 'x' and 'y' values and checks which quadrant each is in, as well as computes the distance between the two sets. It is in a 'for' loop that loops ten times. My professor is asking me to check for the maximum distance of all the points that have been input, and print the maximum value, as well as the set of points that produced that maximum. I am having trouble figuring this part out and I could not find any answers to my specific situation on the internet. Below is my code:

/*============== =============== =============== ==*/
#include <stdio.h>
#include <math.h>

/* Function proto-type declarations */
void where_is_xy(flo at x, float y);
float compute_distanc e(float x1, float y1, float x2, float y2);

/* Function definitions */
void where_is_xy(flo at x, float y) {

/*If statements to test what quadrant the input is*/
if (x > 0 && y > 0)
printf("\n(x, y): (%0.2f, %0.2f) is in the first quadrant\n", x, y);
else if (x < 0 && y > 0)
printf("\n(x, y): (%0.2f, %0.2f) is in the second quadrant\n", x, y);
else if (x < 0 && y < 0)
printf("\n(x, y): (%0.2f, %0.2f) is in the third quadrant\n", x, y);
else if (x > 0 && y < 0)
printf("\n(x, y): (%0.2f, %0.2f) is in the fourth quadrant\n", x, y);
else if (x != 0 && y == 0)
printf("\n(x, y): (%0.2f, %0.2f) is on the x-axis\n(it is an x-intercept)\n", x, y);
else if (x == 0 && y != 0)
printf("\n(x, y): (%0.2f, %0.2f) is on the y-axis\n(it is a y-intercept)\n", x, y);
else
printf("\n(x, y): (%0.2f, %0.2f) is on the origin\n", x, y);

}

float compute_distanc e(float x1, float y1, float x2, float y2) {

/*Expression to determine the distance between two sets of points*/
float d;
d = sqrt((pow((x2 - x1), 2)) + (pow((y2 - y1), 2)));
return (d);
}


int main(void)
{
/*Variable Declarations
'i' is the counting variable in the for loop*/
double x1, y1, x2, y2, d;
int i;
double max = 0;
double min = 0;


/*For loop that repeats ten times for determing the quadrant of the set input by the user*/
for(i = 0; i < 10; i += 1) {
{
printf("\nPleas e Input (x, y): ");
scanf("%lf%lf", &x1, &y1);
where_is_xy(x1, y1); /*Calling up the function*/
}
{
printf("\nPleas e input (x, y): ");
scanf("%lf%lf", &x2, &y2); /*Stored in a different set of variables to work with compute_distanc e*/
where_is_xy(x2, y2);
}
{
d = compute_distanc e(x1, y1, x2, y2);
printf("\nThe distance between (%0.2lf, %0.2lf) and (%0.2lf, %0.2lf) equals: %0.2lf\n", x1, y1, x2, y2, d);
}

}


return (0);
}




=============== =============== =============== =
Any help would be greatly appreciated. I am just completely stuck and don't know where to go from here. Thank you very much.
Sep 27 '18 #1
1 1793
weaknessforcats
9,208 Recognized Expert Moderator Expert
The first thing is to not mix integer and floating point. You can compare integers exactly but floating point, due to rounding, may not compare the way you think it should.


There are double variables used in functions that take float arguments. Double is not float.


There double variables compared to integers.


I suggest you convert everything to int. The comparisons will now work.


When you finish this, repost and I'll look at the code again.
Sep 28 '18 #2

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

Similar topics

1
2892
by: allyn44 | last post by:
Hello--i have inherited a dataset that has records like below: id locationid 1 7 2 3 5 4 5 6 4
1
1245
by: Daylor | last post by:
hi. i want to display page. then check every 10 seconds from the client, if a value in the server is changed WITHOUT RELOADING THE ALL PAGE. if value has change, i want the client to reload the page again.
11
3037
by: Richard Meister | last post by:
Hi, I'd like to define several constants and make sure that all of them are smaller than a given other constant. I thought this could be done by a simple macro. Something like this: #define MAX 999 #define DEF_CHECKED_VAL( name, value) #if (value < MAX) \ #define name MAX \
1
1229
by: Kourosh | last post by:
I have a big loop that checks the value of a checkbox several times (1000+ times) I'm just wondering, would it be any more efficient to save the value of the checkbox outside the loop and the read that variable inside the loop instead? ie, I have this for (var i=0;...) doStuff (form1.checkbox1.checked);
1
1952
by: Eric | last post by:
This is the query which i run when the form load. In tbl_EquipmentChronology there are three variables Equipment1, Equipment2, Equipment3. If Equipment1 and 2 are not empty then the query copy equipment2 value in txt of table tbl_Event. Is it possible i do the same IIF or any other way i check into DLookup. I mean same if in tbl_EquipmentChronology Equipment1, 2 and 3 are not empty it shows the value from Equipment3 in List17. Thanks
1
1457
by: Anirhudra | last post by:
I have a timer and this timer value I have to compare with time chunk about 5 second ... it would be like this Here timercount = what the time I have now .. means now I have 10 sec t = time Chunk 5 if (timercount<=t) sleep 1000 ms always check current timer value with t else
3
2169
bhcob1
by: bhcob1 | last post by:
Hi guys, This is the situation. I have 3 tables, with the following relevent fields tblSubFile (Substantiation Files) - autonumber - Primary Key - Primary Key
0
4304
by: vinodkus | last post by:
dear sir/madam how to check any value in asp that it is null or not Thanks in advance
1
3740
by: Dleary4395 | last post by:
Hello, my question is how to find the minimum value of a set of numbers in a loop. I used a for loop, and the maximum value is always right but the minimum is always 0. I think it's because the minValue is set to 0 to begin with so it thinks it's an input and not just the starter value. This is my code #include <stdio.h> #include <stdlib.h> #define pause system("pause") #define LOOPMAX 5 int main() { int loopCounter = 0;
0
8371
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
8790
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8572
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8652
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
7391
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...
0
4202
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2782
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2017
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.