Prob en C++ avec overloading , please help me. - Programmation
Marsh Posté le 07-03-2002 à 09:06:01
Pourquoi ce prob me dit une error d'embiguiter : #include <iostream> #include <conio> //----FUNCTION DECLARATION SECTION (PROTOTYPES)-- double abs (double Num1); int abs (int Num2); int main() { int Num1 = 5, Num2 = -6, integer = 0; double Real1 = 45.6, Real2 = -77.1, num1 = 0.0; { // Use std as shown below // We discussed this today std::cout << "Please give an integer: "; std::cin >> integer; std::cout << "Please enter a fractional number: "; std::cin >> num1; std::cout<< abs(integer)<<std::endl; std::cout<< abs(num1)<<'\n'; std::cout << abs(Real2)<<std::endl; std::cout << abs(Real1)<<std::endl; std::cout << abs(Num1)<<std::endl; std::cout << abs(Num2)<<std::endl; } getch(); return 0; } //----FUNCTION IMPLEMENTATION SECTION---- double abs (double Num1) { if ( Num1 < 0.0 ) { return -Num1; } return Num1; } int abs (int Num2) { if ( Num2 < 0 ) { return -Num2; } return Num2; }
Marsh Posté le 07-03-2002 à 12:53:06
bah pour ce genre de sport tu t'en tireras bpc mieux avec des templates.....
Make sure you enter the(*)required information where indicate.HTML code is not allowed
Marsh Posté le 07-03-2002 à 09:06:01
Pourquoi ce prob me dit une error d'embiguiter :
#include <iostream>
#include <conio>
//----FUNCTION DECLARATION SECTION (PROTOTYPES)--
double abs (double Num1);
int abs (int Num2);
int main()
{
int Num1 = 5, Num2 = -6, integer = 0;
double Real1 = 45.6, Real2 = -77.1, num1 = 0.0;
{
// Use std as shown below
// We discussed this today
std::cout << "Please give an integer: ";
std::cin >> integer;
std::cout << "Please enter a fractional number: ";
std::cin >> num1;
std::cout<< abs(integer)<<std::endl;
std::cout<< abs(num1)<<'\n';
std::cout << abs(Real2)<<std::endl;
std::cout << abs(Real1)<<std::endl;
std::cout << abs(Num1)<<std::endl;
std::cout << abs(Num2)<<std::endl;
}
getch();
return 0;
}
//----FUNCTION IMPLEMENTATION SECTION----
double abs (double Num1)
{
if ( Num1 < 0.0 )
{
return -Num1;
}
return Num1;
}
int abs (int Num2)
{
if ( Num2 < 0 )
{
return -Num2;
}
return Num2;
}