0

Would this be considered as a Subrountine problem? My program runs but I feel like it is missing something else.

#include <iostream>
using namespace std;
void getData(int, int, int);
 int main()
 {
    int x,y,z;
    cout << "Please enter first number: ";
    cin >> x;
    cout << "Please enter second number: ";
    cin >> y;
    z = x * y;
    cout << "Answer is " << z;

    cout << "\n\nPlease enter first number: ";
    cin >> z;
    z = z+5.0;
    cout << "\nAnswer is: " << z;
    return 0;
    }
2
Contributors
1
Reply
2
Views
4 Years
Discussion Span
Last Post by deceptikon
0

My program runs but I feel like it is missing something else.

Yes, you're missing the subroutine. Declaring a function is only half of process, you also need to define the function and tell it how it works:

#include <iostream>

using namespace std;

// Declaration: Tells the compiler how a function is called
int multiply(int x, int y);

int main()
{
    // You can compile a call to the function with only a declaration,
    // but a definition is required for the code to run.
    std::cout << multiply(5, 2) << '\n';
}

// Definition: Tells the compiler what a function does
int multiply(int x, int y)
{
    return x * y;
}

Edited by deceptikon

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.