Unexplainable Errors

I'm trying to write a code that will find the smaller number between to numbers and print the smaller numbers

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 #include <iomanip>
#include <iostream>
#include "cstdlib"

using namespace std;

double smaller_number (double num1, double num2);

int main ()
{ 
    double num1, num2;
    cout << "Enter the first number: ";
    cin >> num1;
    cout << "Enter the second number: ";
    cin >> num2;
    return 0;
}

double smaller_number (double num1, double num2);
{
    if num1 > num2
        return num1;
    else
        return num2;
}
Last edited on
1
2
3
4
5
6
7
double smaller_number (double num1, double num2) // no semicolon here
{
    if (num1 > num2) // parentheses added
        return num1;
    else
        return num2;
}
You also need to call the function you created after receiving the second user input.

1
2
3
4
5
6
7
8
9
10
int main ()
{ 
    double num1, num2;
    cout << "Enter the first number: ";
    cin >> num1;
    cout << "Enter the second number: ";
    cin >> num2;
    cout << smaller_number(num1, num2); // function called and parameters added
    return 0;
}


Topic archived. No new replies allowed.