3 Replies - 783 Views - Last Post: 20 February 2011 - 06:05 PM Rate Topic: -----

#1 AvidFitness  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 05-February 11

How to fix this error? Due in 30 minutes...

Posted 20 February 2011 - 05:38 PM

I have a feeling I am close to getting this to work. Took me forever. Programming definitely isn't my thing.
Assignment was-
"Please implement concisely and efficiently the following function overloading (in red) which calculates the minimum of different numbers of inputs. OUTPUT all the results into an output file, out.txt. Pack your source code and the output file into exer3.zip and upload it online using Assignments menu."

Error is "Circular minimum3 <- minimum3.dependency droppped."

What does this mean and how do I fix it. Assignment is due in 30 minutes..

#include <iostream>
#include <fstream>
using namespace std;

//Declarations
int min(int, int, int);
int min(int, int, int, int);
int min(int, int, int, int);
ofstream output; 

int main()
{

   cout<< "Minimum of 55 and 66 is: " << min(55, 66) << endl;
   cout<< "Minimum of 99, 77 and 33 is: " << min(99, 77, 33) << endl;
   cout<< "Minimum of 34, 6, 72, and 9 is: " << min(34, 6, 72, 9) << endl;
  
   system("pause");

   return 0;

}

 

 
//Definitions
int min (int num1, int num2)
{
    int minimum = num1;
    if (num2 < minimum)
    {
       minimum = num2;
    }
    
output.open("out.txt", ios::app);
output<<"Minimum of " << num1 <<" " << num2 << " is: " << minimum << endl; //Output results
output.close();

return minimum;

}


int min (int num1, int num2, int num3)
{
    int minimum = num1;
    if (num2 < minimum)
    {
       minimum = num2;
    }
    
    if (num3 < minimum)
    {
       minimum = num3;
    }
    
output.open("out.txt", ios::app);
output<<"Minimum of " << num1 <<" " << num2 <<" " << num3 << " is: " << minimum << endl;
output.close();

return minimum;
}

int min (int num1, int num2, int num3, int num4)
{
    int minimum = num1;
    if (num2 < minimum)
    {
       minimum = num2;
    }
    
    if (num3 < minimum)
    {
       minimum = num3;
    }
    
    if (num4 < minimum)
    {
       minimum = num4;
    }

output.open("out.txt", ios::app);
output<<"Minimum of " << num1 <<" " << num2 <<" " << num3 <<" " << num4 << " is: " << minimum << endl;
output.close();

return minimum;
}



Is This A Good Question/Topic? 0
  • +

Replies To: How to fix this error? Due in 30 minutes...

#2 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1304
  • View blog
  • Posts: 4,489
  • Joined: 19-February 09

Re: How to fix this error? Due in 30 minutes...

Posted 20 February 2011 - 05:57 PM

Only problem seems to be declarations, with too many parameters/arguments in a couple.

//Declarations
int min(int, int);
int min(int, int, int);
int min(int, int, int, int);


Was This Post Helpful? 0
  • +
  • -

#3 jimblumberg  Icon User is offline

  • member icon


Reputation: 3988
  • View blog
  • Posts: 12,301
  • Joined: 25-December 09

Re: How to fix this error? Due in 30 minutes...

Posted 20 February 2011 - 05:58 PM

int min(int, int, int);
int min(int, int, int, int);
int min(int, int, int, int);



You have 3 function prototypes, but 2 are the same. Your function prototypes should match your functions. Do they?




Jim
Was This Post Helpful? 0
  • +
  • -

#4 AvidFitness  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 05-February 11

Re: How to fix this error? Due in 30 minutes...

Posted 20 February 2011 - 06:05 PM

View Postjimblumberg, on 20 February 2011 - 05:58 PM, said:

int min(int, int, int);
int min(int, int, int, int);
int min(int, int, int, int);



You have 3 function prototypes, but 2 are the same. Your function prototypes should match your functions. Do they?




Jim


I guess I messed that one up. I think I messed up more then I think.
Here is what we were given to start out with-
//overmin.cpp

 

#include <iostream>

using namespace std;

 

//       Function Prototypes

//The following are all considered by the compiler

//to be different functions.

 

int min(int, int);

int min(int, int, int);

int min(int, int, int, int);

int min(int, int, int, int, int);

//declare the outfile out.txt here; refer to Module 6 notes for file IO

 

 

int main(){

   cout << "min=  " << min(55, 66) << endl;

   /*cout << "min=  " << min(99, 77, 33)   << endl;

   cout << "min=  " << min(34, 6, 72,9)  << endl;

   cout << "min=  " << min(34, 6, 72, 9, 2) << endl; */

   system("pause");

   return 0;

}

 

 

int min (int x, int y){

if (x>y)

return y;

return x;

}

 

 

int min(int, int, int) {}// Hint: set min to be the first parameter, etc. for concise logic

int min(int, int, int, int){..}

int min(int, int, int, int, int){}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1