All pastes #1272089 Raw Edit

Unnamed

public cpp v1 · immutable
#1272089 ·published 2008-12-01 06:15 UTC
rendered paste body
/************************** Julian Hovind          ** 200271353              ** Assignment 8 Program 3 **proper use of arrays    ** Due: December 2, 2008  ** Date: November 26, 2008** CS110-001 Prof: Ivanov **************************/#include <iostream>#include <fstream>using namespace std;bool isNumInArray(int[], int, int);int userIns(int);int main(){	int numstore[200];	int size = 0;	int val = 0;	ifstream indata;	string file_name;	bool TORF;	int count;		cout << "Please enter the file name: ";	cin >> file_name;		indata.open(file_name.c_str());		if(!indata.is_open())						//makes sure data file exists	{    cout << "error. quitting" << endl;    return(1);	}    else	{  		while (!indata.eof())		// runs loop until no more numbers are in the file		{			indata >> numstore[count];			count  ;		}	}		cout << "Opening " << file_name << " and grabbing all values stored... Done!" << endl;	//lets user know that the file has been opened and numbers are stored	do	//loop goes until user enters 1000  or -1000-	{	val = userIns(val);	//users number to search for	TORF = isNumInArray(numstore, size, val);	//sotres TrueOrFalse value for checking	if (TORF == true)	{		cout << "Number " << val << " is FOUND in the input file." << endl;	}	else if (TORF == false)	{		cout << "Number " << val << " was NOT FOUND in the input file." << endl;	}	//checks if the number is in file or not.	} while (val < 1000 && val > -1000);		cout << "Quitting......." << endl;	indata.close();	return 0;}//-----------------------------------//asks the user for a value//sends value back to main program//Precondition: none//Postcondition:sends value backint userIns(int val){	cout << "Please enter a number to find: ";	cin >> val;		return val;}//-----------------------------------//This function checks the value that the user inputs to see if the value is in //the array and lets the main program know if it is.//Preconditon: takes users entered number//Postcondition: returns true or falsebool isNumInArray(int arr[], int size, int val){	cout << val << endl;	for (int i = 0; i < size; i  )	{		if (arr[i] == val)			return true;	}		return false;}