#include <iostream>
#include <cmath>
usingnamespace std;
int main(void);
int test (int, char, double, int);
int main()
{
int actual;
int a = 5;
char b = 'z';
double c = 7.3;
int d = 5;
actual = test(a, b, c, d);
printf ("The value is ");
return 0;
}
int test(int first, char second, double third, int fourth)
{
int value;
cout << first << "," << second<< ","<< third << ","<< fourth << endl;
cin >> value ;
return value;
}
No, because the function itself likely shouldn't be printing anything nor ask for user input. Edit: I should clarify -- what you did technically works, but your function was not really using the parameters to influence the result. If you had a comment near the function (or near the prototype in your case) explaining what the function was supposed to do, it'd be clearer.
main() is like the user of the function. The user calls it with some parameters, gets a result, and if he wants to print out the result then he'll print it.
You might also want to convert tabs to spaces in your editor ;D
#include <iostream>
usingnamespace std;
int test(int a, char b, double c, int d)
{
return a + (int)b*c / d;
}
int main()
{
int a = 1;
char b = '=';
double c = 2.05;
int d = 3;
int actual = test(a, b, c, d);
cout << actual << endl;
return 0;
}
#include <iostream>
usingnamespace std;
int main(void);
int test (int, char, double, int);
int main()
{
int actual;
int a = 5;
char b = 'z';
double c = 7.3;
int d = 5;
actual = test(a, b, c, d);
}
int test(int first, char second, double third, int fourth)
{
int value;
cout << first << "," << second<< ","<< third << ","<< fourth << endl;
cin >> value ;
return value;
}