GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 04-Nov-2008, 14:41
socal850tuner socal850tuner is offline
New Member
 
Join Date: Oct 2008
Posts: 14
socal850tuner is on a distinguished road

"max" syntax


What does the "max" syntax do in the following statement?

c[i] = max(a[i], b[i])


I'm trying to figure out my homework for my comp sci class and the teacher sucks, so any help would be great.
  #2  
Old 04-Nov-2008, 15:22
n00pster n00pster is offline
Junior Member
 
Join Date: Sep 2008
Location: Miami
Posts: 40
n00pster will become famous soon enough
Talking

Re: "max" syntax


Quote:
Originally Posted by socal850tuner
What does the "max" syntax do in the following statement?

c[i] = max(a[i], b[i])


I'm trying to figure out my homework for my comp sci class and the teacher sucks, so any help would be great.

Not sure what you meant by max syntax. But i guess your teacher might have been using the max function in STL algorithm. From what you posted the element c[i] gets assigned the bigger of the two values of a[i] or b[i].

Best of luck with the home work , study hard
  #3  
Old 04-Nov-2008, 15:28
socal850tuner socal850tuner is offline
New Member
 
Join Date: Oct 2008
Posts: 14
socal850tuner is on a distinguished road

Re: "max" syntax


Thanks dude. So "max" actually does seperate which ever one is bigger? I didn't remember reading anything about "max" in the syntax chapter so I was a concerned.
  #4  
Old 04-Nov-2008, 15:31
dlp dlp is offline
Member
 
Join Date: May 2006
Posts: 157
dlp has a spectacular aura about

Re: "max" syntax


http://www.cplusplus.com/reference/algorithm/max.html

If you see functions like that that you don't understand, you probably want to use the above site. It's pretty handy.
  #5  
Old 04-Nov-2008, 15:35
n00pster n00pster is offline
Junior Member
 
Join Date: Sep 2008
Location: Miami
Posts: 40
n00pster will become famous soon enough

Re: "max" syntax


Quote:
Originally Posted by socal850tuner
Thanks dude. So "max" actually does seperate which ever one is bigger? I didn't remember reading anything about "max" in the syntax chapter so I was a concerned.

check whether he has used a #include <algorithm>
if yes then this is the function, look at the examples given in the link below to get an idea
http://www.cplusplus.com/reference/algorithm/max.html

But may be he just defined the function max as a regular function or as a macro. check where else you can find max() in the code
  #6  
Old 04-Nov-2008, 18:22
socal850tuner socal850tuner is offline
New Member
 
Join Date: Oct 2008
Posts: 14
socal850tuner is on a distinguished road

Re: "max" syntax


Quote:
Originally Posted by dlp
http://www.cplusplus.com/reference/algorithm/max.html

If you see functions like that that you don't understand, you probably want to use the above site. It's pretty handy.

I tried running the sample program on this website. However It kept telling me "max" is an "undeclared identifier." I'm not sure what this means so if you can keep helping me through this that would be great.
  #7  
Old 04-Nov-2008, 20:06
n00pster n00pster is offline
Junior Member
 
Join Date: Sep 2008
Location: Miami
Posts: 40
n00pster will become famous soon enough

Re: "max" syntax


Quote:
Originally Posted by socal850tuner
I tried running the sample program on this website. However It kept telling me "max" is an "undeclared identifier." I'm not sure what this means so if you can keep helping me through this that would be great.

have you copied the entire program including the following lines?
CPP / C++ / C Code:
#include <iostream>
#include <algorithm>
using namespace std;
  #8  
Old 04-Nov-2008, 20:08
socal850tuner socal850tuner is offline
New Member
 
Join Date: Oct 2008
Posts: 14
socal850tuner is on a distinguished road

Re: "max" syntax


yeah I did... I was able to run the sample "max" program from pico/g++ on my school's libra machine though (not on Microsoft visual though).
  #9  
Old 05-Nov-2008, 11:06
dlp dlp is offline
Member
 
Join Date: May 2006
Posts: 157
dlp has a spectacular aura about

Re: "max" syntax


CPP / C++ / C Code:
// max example
#include <iostream>
#include <algorithm>
using namespace std;

int main () {
  cout << "max(1,2)==" << max(1,2) << endl;
  cout << "max(2,1)==" << max(2,1) << endl;
  cout << "max('a','z')==" << max('a','z') << endl;
  cout << "max(3.14,2.72)==" << max(3.14,2.72) << endl;
  return 0;
}

This works fine for me. Visual Studio 2008. Copy and paste your code.
  #10  
Old 05-Nov-2008, 14:11
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,218
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: "max" syntax


Quote:
Originally Posted by socal850tuner
yeah I did... I was able to run...though (not on Microsoft visual though).
Are you using Microsoft Visual C++ version 6? That compiler is pre-standard, and there are many things that don't work (never worked; never will work).

One of those things that is missing is the std::max function from <algorithm> (It is, however, implemented as a macro in the non-standard header <windows.h>.)

There are free downloads of Microsoft compilers. If you are going with Microsoft, I would definitely recommend a current version of Visual Studio Express for learning C++ rather than the buggy old, bewhiskered Version 6

I would start here: http://www.microsoft.com/express/ and follow all instructions. It's kind of lengthy, but you will have the "best" that Microsoft can offer for free.

If you are not running Version 6, tell us exactly what version you are using.

Regards,

Dave
 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Linked Lists advice request promsan C Programming Language 74 23-May-2007 09:29
Syntax question Despoina C++ Forum 3 11-Jul-2006 02:16
syntax errors in document coder MS Visual C++ / MFC Forum 0 11-Mar-2006 05:12
Winsock error when compiling FLTK 2.0 Projects mauriciorossi FLTK Forum 3 16-Aug-2005 11:18
Help with syntax errors PeteGallo C Programming Language 7 08-Aug-2005 21:30

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 16:03.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.