# Program to find the maximum of three floating number

Page 1 of 1

## 7 Replies - 24846 Views - Last Post: 20 April 2010 - 01:34 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=54123&amp;s=3edfa95b645e9129c60f428a819f4e96&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 lasharme

Reputation: 0
• Posts: 6
• Joined: 14-May 08

# Program to find the maximum of three floating number

Posted 07 June 2008 - 09:48 AM

```/****************************************************/
/* File: Float.cpp								  */
/*												  */
/* Created by: LaSharme Hutchins					*/
/* Date: June 6, 2008							   */
/*												  */
/* Program to find the maximum of three			 */
/* floating point numbers						   */
/*												  */
/* Inputs: (keyboard)							   */
/*   Three floating point numbers (n & k)		   */
/*												  */
/* Output:										  */
/*   Print the largest value on the screen		  */
/*												  */
/* Algorithm: uses a programmer defined			 */
/* function maximum to determine and				*/
/* return the largest of three					  */
/* floating point numbers						   */
/*												  */
/* See additional notes for A5					  */																			 */										  */
/****************************************************/

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

float maximum (float, float, float );  /* Prototype for maximum function */

int main()
{
float 1, 2, 3;
cout << "Enter three floating-point numbers: ";
cin >> number1 >> number2 >> number3;

// number1, number2 and number3 are arguments to
// the maximum function call
cout << "Maximum is: " << maximum( 1,2,3 ) << endl;

return 0; //indicates successful termination
}

} // end main

// Function maximum definition;
// x, y and z below are parameters to
// the maximum function definition
float maximum( float x, float y, float  z )
{
float max = x;

if ( y > max )
max = y;

if ( z > max )
max = z;

return max; //max is largerst value

} //end function maximum
}
```

#### Attached File(s)

This post has been edited by NickDMax: 07 June 2008 - 01:21 PM

Is This A Good Question/Topic? 0

## Replies To: Program to find the maximum of three floating number

### #2 perfectly.insane

Reputation: 70
• Posts: 644
• Joined: 22-March 08

## Re: Program to find the maximum of three floating number

Posted 07 June 2008 - 10:06 AM

Did you have a question?

I assume that you are, and here are a few hints:

Braces must also be in pairs (Each { requires a }, and vice versa).

### #3 S0n1C

Reputation: 3
• Posts: 46
• Joined: 15-June 07

## Re: Program to find the maximum of three floating number

Posted 08 June 2008 - 02:35 PM

I tried compiling your code and I got 15 errors that I was to lazy to to fix, so I wrote my own. Was your question regarding any of your errors? or what, because I created my own, using your ideas and it works fine. In your code you have 1 extra closing brace on both functions that you don't need. also in ur function definition its a good idea to include variable names, in your case:
```#include <iostream>

using std::cout;
using std::cin;
using std::endl;

float maximum (float x, float y, float z);

```

a couple more things. Why are you using
```using std::cout;
using std::cin;
using std::endl;

```

why don't you just use
```using namespace std;

```

and

I don't know if your forces to use floats, but if you have a choice I would suggest that you use doubles instead. Without going into detail, they are more used these days than floats.

Hope that this helped, post more if you need more help

S0n1C!

### #4 gabehabe

• GabehabeSwamp

Reputation: 1433
• Posts: 11,006
• Joined: 06-February 08

## Re: Program to find the maximum of three floating number

Posted 08 June 2008 - 02:57 PM

I cleaned up your code, and commented where your errors were coming from.
```/****************************************************/
/* File: Float.cpp                                  */
/*                                                  */
/* Created by: LaSharme Hutchins                    */
/* Date: June 6, 2008                               */
/*                                                  */
/* Program to find the maximum of three             */
/* floating point numbers                           */
/*                                                  */
/* Inputs: (keyboard)                               */
/*   Three floating point numbers (n & k)           */
/*                                                  */
/* Output:                                          */
/*   Print the largest value on the screen          */
/*                                                  */
/* Algorithm: uses a programmer defined             */
/* function maximum to determine and                */
/* return the largest of three                      */
/* floating point numbers                           */
/*                                                  */
/* See additional notes for A5                      */ // you had some stray /* tags
/****************************************************/

#include <iostream>

using namespace std;

float maximum (float, float, float );  /* Prototype for maximum function */

int main()
{
float a,b,c; //cant just be numbers for names
cout << "Enter three floating-point numbers: ";
cin >> a >> b >> c;

// number1, number2 and number3 are arguments to
// the maximum function call
cout << "Maximum is: " << maximum( a,b,c ) << endl;

return 0; //indicates successful termination

} // end main

// Function maximum definition;
// x, y and z below are parameters to
// the maximum function definition
float maximum( float x, float y, float  z )
{
float max = x;

if ( y > max )
max = y;

if ( z > max )
max = z;

return max; //max is largerst value

} //end function maximum
// extra }
```

Hope this helps

Reputation: 0
• Posts: 2
• Joined: 16-October 08

## Re: Program to find the maximum of three floating number

Posted 03 September 2009 - 12:32 PM

lasharme, on 7 Jun, 2008 - 08:48 AM, said:

```/****************************************************/
/* File: Float.cpp								  */
/*												  */
/* Created by: LaSharme Hutchins					*/
/* Date: June 6, 2008							   */
/*												  */
/* Program to find the maximum of three			 */
/* floating point numbers						   */
/*												  */
/* Inputs: (keyboard)							   */
/*   Three floating point numbers (n & k)		   */
/*												  */
/* Output:										  */
/*   Print the largest value on the screen		  */
/*												  */
/* Algorithm: uses a programmer defined			 */
/* function maximum to determine and				*/
/* return the largest of three					  */
/* floating point numbers						   */
/*												  */
/* See additional notes for A5					  */																			 */										  */
/****************************************************/

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

float maximum (float, float, float );  /* Prototype for maximum function */

int main()
{
float 1, 2, 3;
cout << "Enter three floating-point numbers: ";
cin >> number1 >> number2 >> number3;

// number1, number2 and number3 are arguments to
// the maximum function call
cout << "Maximum is: " << maximum( 1,2,3 ) << endl;

return 0; //indicates successful termination
}

} // end main

// Function maximum definition;
// x, y and z below are parameters to
// the maximum function definition
float maximum( float x, float y, float  z )
{
float max = x;

if ( y > max )
max = y;

if ( z > max )
max = z;

return max; //max is largerst value

} //end function maximum
}
```

Reputation: 0
• Posts: 2
• Joined: 16-October 08

## Re: Program to find the maximum of three floating number

Posted 03 September 2009 - 12:38 PM

Your code has an error as you are not comparing the second input with the third.
For ex: if the input is 13 14 12, you might still get the max of these 3 numbers as 13.

Reputation:

## Re: Program to find the maximum of three floating number

Posted 20 April 2010 - 12:28 AM

Find the factorial of a number using for loop and while loop

### #8 aniri

Reputation: 54
• Posts: 657
• Joined: 24-November 09

## Re: Program to find the maximum of three floating number

Posted 20 April 2010 - 01:34 AM

moon..moon, on 20 April 2010 - 08:28 AM, said:

Find the factorial of a number using for loop and while loop

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Thank you for helping us helping you.

This post has been edited by aniri: 20 April 2010 - 01:35 AM