Void type function to find the maximum of three given integer numbers"

In summary, the problem is that the student doesn't know how to write a program to find the maximum of three given integers. The student is looking for help, and thanks to the expert, they were able to produce a program that calls a void type function to find the maximum.
  • #1
frogdogbb
45
0
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.
 
Physics news on Phys.org
  • #2
Well this is a pretty simple problem...
Code:
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.
 
Last edited:
  • #3
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...
 
  • #4
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;
}
 
  • #5
re

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()...
 
  • #6
Thanks a lot

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;
}
 
  • #7
I think this looks sexy.


Code:
#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;
}
 
  • #8
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.
 
  • #9
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.
 
  • #10
frogdogbb said:
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
 
  • #11
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.
 

1. What is a "void type function"?

A void type function is a function in programming that does not return any value. It is used to perform a certain task or operation without needing to output a value.

2. How does a void type function find the maximum of three given integer numbers?

A void type function for finding the maximum of three given integer numbers uses conditional statements and comparison operators to compare the three numbers and determine which one is the largest.

3. Can a void type function find the maximum of more than three numbers?

Yes, a void type function can be designed to find the maximum of any number of given integer numbers, not just three. However, the function would need to be modified to handle a larger number of inputs.

4. What happens if two or more of the given numbers are equal?

If two or more of the given numbers are equal, the void type function would return one of the equal numbers as the maximum. This is because the function would compare each number with the current maximum and update the maximum if a larger number is found.

5. Are there any limitations to using a void type function for finding the maximum of three given integer numbers?

One limitation of using a void type function for finding the maximum of three given integer numbers is that it can only compare and determine the maximum of the given numbers. It cannot perform any other operations or return any other values. Additionally, the function may need to be modified if the data type of the numbers is changed or if the function needs to handle a larger number of inputs.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
2
Views
933
  • Engineering and Comp Sci Homework Help
Replies
21
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
12
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
945
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
840
  • Engineering and Comp Sci Homework Help
Replies
13
Views
2K
  • Precalculus Mathematics Homework Help
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
Back
Top