-1

Here are the codes that I have learned from Youtube, but after I run it, it is blank on the small screen:

#include <iostream>
#include <cmath>

using namespace std;
    
int getMin(int num1, int num2) {
    int answer;
    if (num1 < num2) {
        answer = num1;
    } else {
        answer = num2;
    }
    return answer;
}
    
    
int main() {
    getMin(3,5);
    return 0;
}
Casey
  • 10,297
  • 11
  • 59
  • 88
hdhdkl
  • 9
  • 4
    you don't print the result... – mediocrevegetable1 Mar 19 '21 at 05:01
  • 1
    ⟼Remember, it's always important, *especially* when learning and asking questions on Stack Overflow, to keep your code as organized as possible. [Consistent indentation](https://en.wikipedia.org/wiki/Indentation_style) helps communicate structure and, importantly, intent, which helps us navigate quickly to the root of the problem without spending a lot of time trying to decode what's going on. – tadman Mar 19 '21 at 05:03
  • 3
    YouTube is the singularly worst place to learn C++. I'd strongly advise against it. Get a [good reference book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) you can depend on to provide *in depth* answers to your questions. C++ is a monster of a programming language, it is not something you can just walk into and pick up one ten minute "tutorial" at a time. If you prefer video, don't forget **free, high quality resources** like [Khan Academy](https://www.khanacademy.org) exist! – tadman Mar 19 '21 at 05:04
  • 1
    Thanks for your precious advice @tadman ! – hdhdkl Mar 19 '21 at 05:11

1 Answers1

1
#include <iostream>

using namespace std;

 int getMin(int num1, int num2){

 if (num1 < num2)
    return num1;
 else 
   return num2;
 }


 int main (){
     cout<<getMin (3,5); // Result of getmin(3,5)
return 0;
}

You're passing the argument to a function that has a return value but when the function is returning the value you're not storing that value anywhere or printing it. You can store that value in a variable and can print directly like in the above code.

iamdhavalparmar
  • 1,090
  • 6
  • 23