S
Steph W.
Hello,
I had a quick question about using istream/cin as a function parameter. I'mworking on a homework problem that is requiring me to create a recursive function called Max that returns the max value of a sequence of numbers thatis entered in by the user. We are not allowed to use any type of data structure and thats why I chose to use istream/cin. Here is what I have so far:
#include <iostream>
#include <istream>
using namespace std;
int MAX(istream x);
int main()
{
int number;
char option;
cout << "This program will print out the maxium value that the user inputs..";
do
{
cout <<"Enter in values to find the maxium number. Enter in -1 to stop: ";
cout << MAX(cin) << endl;
cout <<"Would you like to run the program again? (Y/N): ";
cin >> option;
}while(toupper(option) =='Y');
return 0;
}
int MAX(istream x)
{
int largest =0;
if (x <= 0)
return largest;
if ((x % 2 == 0) && (largest < x)) //IntelliSense: no operator "%" matches these operands
{
largest = x; // IntelliSense: no suitable conversion function from "std::istream" to "int" exists
return MAX(x);
}
else
MAX(x);
return return largest;
}
Thank you in advance for any advice.
I had a quick question about using istream/cin as a function parameter. I'mworking on a homework problem that is requiring me to create a recursive function called Max that returns the max value of a sequence of numbers thatis entered in by the user. We are not allowed to use any type of data structure and thats why I chose to use istream/cin. Here is what I have so far:
#include <iostream>
#include <istream>
using namespace std;
int MAX(istream x);
int main()
{
int number;
char option;
cout << "This program will print out the maxium value that the user inputs..";
do
{
cout <<"Enter in values to find the maxium number. Enter in -1 to stop: ";
cout << MAX(cin) << endl;
cout <<"Would you like to run the program again? (Y/N): ";
cin >> option;
}while(toupper(option) =='Y');
return 0;
}
int MAX(istream x)
{
int largest =0;
if (x <= 0)
return largest;
if ((x % 2 == 0) && (largest < x)) //IntelliSense: no operator "%" matches these operands
{
largest = x; // IntelliSense: no suitable conversion function from "std::istream" to "int" exists
return MAX(x);
}
else
MAX(x);
return return largest;
}
Thank you in advance for any advice.