| linklink24 (6) | |
|
Hey guys I need help finding the smallest and biggest number. All of the numbers are in one file. Then I need to create a file to output the result. There are 7 different numbers to analyze that the program reads. I just can't seem to get the biggest number or the smallest. Also I cant use an array (teacher said). I asked my classmates and told me to use this: for (int i=0;i<7;i++) ^ but I dont know where to go from there.. Thank you in advance! #include "StdAfx.h" #include <iostream> #include <fstream> #include <iomanip> #include <string> using namespace std; int main () { int num1; int num2 ; int num3; int num4; int num5; int num6; int num7; int total; float average; int max; int min; ifstream thefile("file1.txt"); ofstream thefile2; thefile2.open("file2.txt"); if(thefile.is_open()){ while (thefile>>num1>>num2>>num3>>num4>>num5>>num6>>num7){ total = num1+num2+num3+num4+num5+num6+num7; average=total/7; for (int i=0;i<7;i++) thefile2<<num1<<"\t"<<num2<<"\t"<<num3<<"\t"<<num4<<"\t"<<num5<<"\t"<<num6<<"\t"<<num7<<":"<<endl; cout<<endl; thefile2<<"The total for the line above is: "<<total<<endl; thefile2<<"The average for the line above is: "<<average<<endl; thefile2<<"The biggest number is: "<<endl; thefile2<<"The smallest number is: "<<endl; thefile2<<endl; } } system("pause"); return 0; } | |
|
|
|
| Moschops (5981) | |
|
Read a number. Is it the biggest so far? Make a note of it if it is. Repeat until no more numbers to be read. | |
|
|
|