Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming

Reply
 
LinkBack Thread Tools
Old 10-05-09   #1 (permalink)
New to Overclock.net
 
Join Date: Oct 2009
Posts: 1

Rep: 0 tsmith118 Unknown
Unique Rep: 0
Trader Rating: 0
Default Help with Minimum Program in C++

I need help writing a program to output a minimum of a set of data.
my input file is 99 77 33 55 66 33.3 34 6.0 7.2 3.4 6 7.2 3.4 6.0 7.2
my ouput before i commented out looked as follows:
X Y Z Minimum

99.0 77.0 33.0
55.0 66.0 33.3
34.0 6.0 7.2
3.4 6.0 7.2
3.4 6.0 7.2
Right now as it is written, my code will output my minimum as follows:
33
33.3
6
3.4
3.4

All of that is right, I just need to combine the 2. I am trying to create an output data file so I can then read that data back into the output file I need. Can anyone offer any suggestions?

Note, the code part that is commented out produces an error of redefinition of `int main()'

Code:
#include <fstream> 
#include <iomanip>
#include <iostream> 

using namespace std;
ofstream outfile("min.dat""out.txt");
int main(); 


int min(int x, int y, int z)
//99, 77, 33
{
    if (x>y)
    if (y>z) return z;
    else return y;
    else
    if (x>z) return z;
    else return x;
    
    }


double min(int x, int y, double z)
//55, 66, 33.3
{
       if (x>y)
       if (y>z) return z;
       else return (double)y;
       else 
       if (x>z) return z;
       else return (double)x;
       }
double min(int x, double y, double z)
//34, 6.0, 7.2
{
       if (x>y)
       if (y>z) return z;
       else return y;
       else 
       if (x>z) return z;
       else return (double)x;
       } 
double min(double x, int y, double z) 
//3.4, 6, 7.2
{
       if (x>y)
       if (y>z) return z;
       else return (double)y;
       else 
       if (x>z) return z;
       else return x;
       }
double min(double x, double y, double z)
//3.4, 6.0, 7.2
{
       if (x>y)
       if (y>z) return z;
       else return y;
       else 
       if (x>z) return z;
       else return x;
       }             
           

int main()

{

   outfile << min(99, 77, 33)   << endl;

   outfile << min(55, 66, 33.3) << endl;

   outfile << min(34, 6.0, 7.2) << endl;

   outfile << min(3.4, 6, 7.2)  << endl;

   outfile << min(3.4, 6.0, 7.2)<< endl;
 
   return 0;

}
/*
ifstream infile("in.dat");

struct record{
       double x;
       double y;
       double z;
};
int main(){
    record rec;
    float min;
if(!infile)
cerr<<"Error:could not open input file\n";
else if(!outfile)
cerr<<"Error:could not open output file\n";
outfile<<setw(9)<<"X"<<setw(10)<<"Y"<<setw(10)<<"Z"<<setw(17)<<"Minimum\n\n";
while(infile >> rec.x >> rec.y >> rec.z){
             outfile<<setiosflags(ios::showpoint | ios::fixed)
             <<setprecision(1)<<setw(10)<<rec.x<<setw(10)<<rec.y<<setw(10)<<rec.z<<setw(12)<<endl;
             }             
return 0;
}
*/
tsmith118 is offline   Reply With Quote
Old 10-05-09   #2 (permalink)
AMD Overclocker
 
decompiled's Avatar
 
amd nvidia

Join Date: Feb 2006
Location: Redsox Nation
Posts: 704

Rep: 78 decompiled is acknowledged by some
Unique Rep: 68
Hardware Reviews: 9
Trader Rating: 0
Default

Some sample code for your main and min(). Remember that int's fall within the scope of float & double so you don't need to override your functions. A single function signature will work in this case.

Code:
#include <iostream>
using namespace std;

float m(float a, float b, float c)
{
  float temp = (a < b ? a : b);
  float answer = (temp < c ? temp : c);
  return answer;
}

int main()
{
  cout << m(80,1.9,3.33333) << endl;
  return 0;
}

System: Slow Poke
CPU
AMD X2 4400
Motherboard
MSI K8N Diamond +
Memory
3gb TCC5
Graphics Card
eVGA 7900GS
Hard Drive
74gb Raptor + Raid 1 640's
Sound Card
Audigy SE
Power Supply
OCZ 600 ModXstream
Case
Antec 1200
CPU cooling
Stock AMD
GPU cooling
Stock eVGA
OS
Windows 7 FTW Edition
Monitor
Dell 1905FP
decompiled is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -5. The time now is 08:55 PM.


Overclock.net is a Carbon Neutral Site Creative Commons License

Terms of Service / Forum Rules | Privacy Policy | DMCA Info | Advertising | Become an Official Vendor
Copyright © 2009 Shogun Interactive Development. Most rights reserved.
Page generated in 0.10016 seconds with 8 queries