Code:
#include <iostream>
using namespace std;
float dividethesenumbers(int x, int y){
return x/y;
}
int main()
{
int x;
int y;
cout << "2 numbers to be divided. \n First number: ";
cin >> x;
cout << "Second number: ";
cin >> y;
cout << dividethesenumbers(x,y) << endl;
system("pause");
return 0;
}
I'm still very wet behind the ears with C++, please bear with.
I was going over function prototypes, to further remember the syntax, and came accross something I can't quite figure out.
Using the above code, I compiled and used 22 for x and 7 for y. (Pi) Instead of getting 3.14......, I got 3.
dividethesenumbers is supposed to return a float, right? I know I used integers for x and y as input but I thought the function would return the type I told it to.
I know the fix is to replace the int x, int y with float x, float y (as well as in main()) but I don't understand why my function won't return the type I ask.