The question says to get the returned values from functions and print it in main.
The final output should be
5
6.2832
3.1416
1. Is the first output the best way to do that in my code
2. How do I output the other 2?
Question in my tutorial
Write a C++ program
a. Create two functions.
i. First function will return number 5 to main function.
ii. Second function will define pi as a constant value of type double
3.1416 and returns pi* 2 to main function.
b. Define each function in namespace
i. Namespace n1 holds first function
ii. Namespace n2 holds second function
c. Call these function inside main function
d. Print pi value inside main function
Output:
5
6.2832
3.1416
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 26
|
namespace n1 {
int function1 () {
return 5;
}
}
namespace n2 {
int function2 () {
const double pi=3.1416;
return pi*2;
}
}
int main () {
{
using namespace n1;
int p;
p=function1();
cout<<p;
}
{
using namespace n2;
cout<<
}
}
|