PDA

View Full Version : C++ help


frogdogbb
Oct7-05, 02:43 PM
I have to answer a homework problem due today that I am not sure how to do the problem reads.
"Write a program that calls a void type function to find the maximum of three given integer numbers"
We use visual basic studio, any help would be appreciated.

mr_coffee
Oct7-05, 02:49 PM
Well this is a pretty simple problem...



void max(int x, int y, int z)
{
int max;
max=x;
if(y>max)max=y;
if(z>max)max=z;
cout<<"max b.itches: " << max<<endl;
}


Also there is no such thing as visual basic studio...
its Visual Studio, Visual basic is a programming lang.

frogdogbb
Oct7-05, 03:19 PM
yea I meant v-studio.net my brain is fried right now trying to figure this out.
I put what you gave me into the program and complied it with #include<iostream>
using namespace standard;
but there is no main function so how do I write it so that it will compile and run?
By the way nice job on the b.itches.....

mezarashi
Oct7-05, 03:32 PM
Uh hmm... don't they teach that in your first class? Every program must have 1 and only 1 main function ^^

//put the funciton declaration and prototype outside of the main function

int main ()
{

//call the function: sample integers 1,2,3.
max(1, 2, 3);

return 0;
}

waht
Oct7-05, 03:35 PM
You need put the function header right after <iostream>, with a semicolon. And nice cout statement by the way.


#include <iostream>

using namespace std;

void max(int x, int y, int z);

.....rest

int main()...

frogdogbb
Oct7-05, 03:41 PM
Well they don't teach us anything in class because the university decieded it would be a good idea to have the class online. Brilliant of them I think, I live 65 miles from the campus and if I need help before I am scheduled to be on campus then I am basically screwed. I knew I needed a main function but could not get the call to work I think I was missing ;'s, here is what I came up with thanks to you. Is it considered good form?
// 7.3.cpp : Defines the entry point for the console application.
#include <iostream>
using namespace std;
void max(int x, int y, int z)
{
int max;
max=x;
if(y>max)max=y;
if(z>max)max=z;
cout<<"max= " << max<<endl;
}
int main ()
{
void max (int x, int y, int z);
max(54, 27 ,35);

return 0;
}

mr_coffee
Oct7-05, 03:48 PM
I think this looks sexy.



#include <iostream>
using namespace std;

void max (int x, int y, int z);

int main ()
{

max(54, 27 ,35);

return 0;
}

void max(int x, int y, int z)
{
int max;
max=x;
if(y>max)max=y;
if(z>max)max=z;
cout<<"max= " << max<<endl;
}

frogdogbb
Oct7-05, 04:34 PM
Ah yes and I see why, The book says it is acceptable to put the main statement after the functions but your looks much better and your spacing makes it look nice and coherant. Thanks again for your help.

mr_coffee
Oct7-05, 08:21 PM
Np. you will find out the more you work with it, pretty soon you will be putting all your function defintions and declations in different files insteedof putting everything with the main function. Then it will become neater.

abdo375
Oct15-05, 03:38 PM
Well they don't teach us anything in class because the university decided it would be a good idea to have the class online. Brilliant of them I think, I live 65 miles from the campus and if I need help before I am scheduled to be on campus then I am basically screwed.

I am sorry Frogdogbb that is not an excuse c++ is a pretty simple language to learn the basics of, most people learn it from the internet or the local library
you just need to study it more

mr_coffee
Oct16-05, 10:04 AM
I taught myself C++ when i was 14, so this is true! but it took several years for me to get comfortable with it. Now i hate programming, it doesn't take long to get burned out with it.