7 Replies - 19797 Views - Last Post: 20 April 2010 - 01:34 AM Rate Topic: -----

#1 lasharme  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 70
  • View blog
  • 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:

C-style comments cannot be nested, and must always have a start with an end (/*, */).

Variable names must not start with a number.

Braces must also be in pairs (Each { requires a }, and vice versa).
Was This Post Helpful? 0
  • +
  • -

#3 S0n1C  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • 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!
Was This Post Helpful? 0
  • +
  • -

#4 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1384
  • View blog
  • Posts: 10,962
  • 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

// had an extra }

} // 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 :)
Was This Post Helpful? 0
  • +
  • -

#5 adi_9833  Icon User is offline

  • New D.I.C Head

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

Re: Program to find the maximum of three floating number

Posted 03 September 2009 - 12:32 PM

View Postlasharme, 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
}

Was This Post Helpful? 0
  • +
  • -

#6 adi_9833  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#7 Guest_moon..moon*


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
Was This Post Helpful? 0

#8 aniri  Icon User is offline

  • D.I.C Addict
  • member icon

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

Re: Program to find the maximum of three floating number

Posted 20 April 2010 - 01:34 AM

View Postmoon..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

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1