// Write a function that take an int and a pointer to an int and
// returns the larger of the int value of the value to which the
// pointer points. What type should you use for the pointer?
#include <iostream>
using std::cout;
using std::cin;
int larger_one(constint i, constint *const p)
{
return (i > *p) ? i : *p;
}
int main()
{
int i;
cin >> i;
cout << larger_one(i, &i);
return 0;
}
Ahh okay I understand what I was missing and was doing wrong. Thank you so much. Plenty of thumbs up. New and improved code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
usingnamespace std;
int larger_one(constint i, constint *const p)
{
return (i > *p) ? i : *p;
}
int main()
{
int i{}, j{};
cout << "Please enter two numbers (pressing enter in between) and enter when done: " << endl;
cin >> i;
cin >> j;
cout << "\nThe larger of the two are: " << larger_one(i, &j);
return 0;
}
Please enter two numbers (pressing enter in between) and enter when done:
4
5
The larger of the two are: 5