1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C++ help

  1. Oct 7, 2005 #1
    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.
     
  2. jcsd
  3. Oct 7, 2005 #2
    Well this is a pretty simple problem...


    Code (Text):

    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: Oct 7, 2005
  4. Oct 7, 2005 #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.....
     
  5. Oct 7, 2005 #4

    mezarashi

    User Avatar
    Homework Helper

    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;
    }
     
  6. Oct 7, 2005 #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()...
     
  7. Oct 7, 2005 #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;
    }
     
  8. Oct 7, 2005 #7
    I think this looks sexy.


    Code (Text):

    #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;
    }
     
     
  9. Oct 7, 2005 #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.
     
  10. Oct 7, 2005 #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.
     
  11. Oct 15, 2005 #10
    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
     
  12. Oct 16, 2005 #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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: C++ help
  1. C\C++ help needed (Replies: 2)

  2. Help with C++ strings (Replies: 3)

Loading...