|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 | |
|
Member (10 bit)
Join Date: Mar 2006
Location: Maryland
Posts: 550
|
Right now i'm enrolled in a course introducing C++. Before I enrolled, I had alot of experience with C++ so the course is quite easy for me but I've now hit a brick wall in this project i'm currently writing.
For this project, we have to... Quote:
Below is the link to the code that I have written up so far.. project7.pdf
__________________
Kerberos2: Corsair Obsidian 700D ASUS M4A89TD Radeon HD 5850 A-DATA 8GB DDR3 1333 AMD Phenom II x6 1055T @ 2.8GHz w/ Corsair H50 Corsair 850HX PSU WD Blue 160GB 7200 RPM SATA HDD WD Black 640GB 7200 RPM SATA HDD ASUS DVD/CD Drive |
|
|
|
|
|
|
#2 |
|
Member (11 bit)
|
Why cant you create a second array to hold ALL the numbers which are in the file. Then take the first 15 while also checking if any one of em is the sentinel.
|
|
|
|
|
|
#3 |
|
Member (9 bit)
Join Date: Feb 2005
Posts: 392
|
ok,
to limit the number of inputs to 15 integers just change the while loop's condition a bit: while((temp_store != 0) && (count <=15)) - ==============>>just add this part and to count the numbers of INTEGERs exceeding 15, do: while(!eof) read and count each; after you done with the first 15 numbers. *************************** however, the way I understand the Project's statement is that: readEchoStore is a FUNCTION, NOT an array. should be declare as: void readEchoStore(ifstream &); the input file name is suppose to be passed as reference to it, like this: readEchoStore(inName); also "inName" the input filename shouldnot be fixed, should be declare as: char *inName; instead.
__________________
words to live by: others don't know, I know. others know, I know more. others know more, I excel. one shouldnt read this far; above, is meant as an encouragement, translated from a Chinese Proverb. "He who angers you conquers you." : Elizabeth Kenny Last edited by alfie2; 04-10-2007 at 03:22 PM. |
|
|
|
|
|
#4 |
|
Moderator
Staff
Premium Member
Join Date: Aug 2003
Location: Richmond, VA
Posts: 7,835
|
You can create an if/else structure inside the while loop. The while-loop will execute until the '0' sentinel arrives (alternatively, and probably more efficiently, you can use a do-while loop structure instead). Create a new boolean variable that will essentially act as an error-check statement. Place the if structure on the count++, where it will run until count==15. Label the boolean true. Else, label the boolean false. Make the true/false boolean as part of the while/do-while loop condition.
kram
__________________
"For today, goodbye. For tomorrow, good luck. And forever, Go Blue!"
University of Michigan President Mary Sue Coleman Last edited by kram 2.0; 04-10-2007 at 09:02 PM. |
|
|
|
|
|
#5 |
|
Member (10 bit)
Join Date: Mar 2006
Location: Maryland
Posts: 550
|
I got as far as creating a reference function and putting all the processing in there but now i'm required to create two more functions. I have a new updated file of my source code below.
Project7.pdf What i'm to do is create two more functions that will calculate the sum and calculate the min & max. How do I go about creating those fucntions and passing the variable needed from function readEchoStore to the other two functions? Would I use a reference function? |
|
|
|
|
|
#6 |
|
Member (9 bit)
Join Date: Feb 2005
Posts: 392
|
you are still using "readEchoStore" as an array, no no no,
you should have array with another name like "storagearray" or whichever you wish, just dont use "readEchoStore" as an array name. here are the two functions: void arrayMaxMin(const int iarray[], int &imax, int &imin) { int i; //find maxium value in array: imax = iarray[0]; for(i=1;i<=14;i++) { if(iarray[i]>imax) imax=iarray[i]; } // find minium value in array: imin = iarray[0]; for(i=1;i<=14;i++) { if(iarray[i]>imin) imin=iarray[i]; } }// arrayMaxMin int arraySum(const int iarray[]) { int i; int total=0; for(i=0;i<=14;i++) total = total +iarray[i]; return total; }//arraySum ========================================= now you can use these two functions inside "readEchoStore" function: void readEchoStore(infile) { int storagearray[VARIABLE]; int highest,lowest; : : : arrayMaxMin(storagearray, highest,lowest); sum = arraySum(storagearray); cout << endl; cout << "\nThe number of integers entered was " << count < cout << "The maximum integer is " << highest << endl; cout << "The minimum integer is " << lowest << endl; } |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|