Sunday, July 14, 2013

Using istream in as a function parameter

Newsgroup: comp.lang.c++

Subject: Using istream in as a function parameter

From: "Steph W." <swilks06@...>

Date: Sun, 14 Jul 2013 14:44:33 -0700 (PDT)



Hello,



I had a quick question about using istream/cin as a function parameter. I'm working 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 that is 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.







via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?42252-Using-istream-in-as-a-function-parameter&goto=newpost

View all the progranning help forums at:

http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums

No comments:

Post a Comment