Could someone show me what is wrong with this code in-order to make it work when compiling under Visual C++ 2008.
It will compile and run "PERFECTLY" under Dev-C++ 5.0. It gives no warnings and no errors because the code is A-OK . .. but under Visual C++ 2008 it gives me a zillion errors and warnings.
It's like nearly everything I try under Dev-C++ 5.0 that turns out perfect, Visual C++ 2008 always got something to say about it by dishing out a bunch of error and warning, than it will not compile the code.
I placed the complete Visual C++ 2008 build-log (error report) at the bottom of the code in the code section below.
Code:// ............................................... How-to switch-CASE.cpp #include <iostream> #include <iomanip> using namespace std; // for iostream using std::cout; using std::cin; using std::endl; using std::setprecision; // for iomanip using std::fixed; int main() { int product; int quantity; double product1 = 23.84; double product2 = 13.5; double product3 = 119.76; double product4 = 251.44; double product5 = 13.74; double total = 0; ///////////////////////////// ///////////////////////////// step - 1 ///////////////////////////// cout << "\nProduct 1 = $ " << product1 << "\nProduct 2 = $ " << fixed << setprecision( 2) << product2 << "\nProduct 3 = $ " << product3 << "\nProduct 4 = $ " << product4 << "\nProduct 5 = $ " << product5 << endl << endl; total = total + ( product1 + product2 + product3 + product4 + product5); cout << total << endl << endl << endl; total= 0; ///////////////////////////// ///////////////////////////// step - 2 ///////////////////////////// cout << "Enter product number 1 - 5 : "; while (!(cin >> product)) { cout << "\nPlease enter ( 1 - 5 ) or to EXIT type -1\n\n" << endl; cin.clear(); cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); cout << "Enter product number 1 - 5 : "; } ///////////////////////////// ///////////////////////////// step - 3 ///////////////////////////// while ( product != -1 ) { switch ( product ) { case 1: cout << "\n\nEnter quantity sold : "; cin >> quantity; cout << endl; total = total + ( product1 * quantity ); break; case 2: cout << "\n\nEnter quantity sold : "; cin >> quantity; cout << endl; total = total + ( product2 * quantity ); break; case 3: cout << "\n\nEnter quantity sold : "; cin >> quantity; cout << endl; total = total + ( product3 * quantity ); break; case 4: cout << "\n\nEnter quantity sold : "; cin >> quantity; cout << endl; total = total + ( product4 * quantity ); break; case 5: cout << "\n\nEnter quantity sold : "; cin >> quantity; cout << endl; total = total + ( product5 * quantity ); break; case '\n': case '\t': case ' ': break; default: // catch any other characters cout << "\nPlease enter ( 1 - 5 ) or to EXIT type -1\n\n" << endl; break; } ///////////////////////////// ///////////////////////////// step - 4 ///////////////////////////// Pick up from "quanity sold" == ERROR correction cout << "Enter product number 1 - 5 : "; while (!(cin >> product)) { cout << "Incorrect entry: Try again\n" << endl; cin.clear(); cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); cout << "Enter product number 1 - 5 : "; } //endWHILE ///////////////////////////// ///////////////////////////// step - 5 ///////////////////////////// } cout << "\n\n\nT O T A L : $" << fixed << setprecision( 2 ) << total << endl<< endl<< endl; system("pause"); system ("CLS"); return main(); return 0; } // ------ Build started: Project: vc--switch-CASE, Configuration: Debug Win32 ------ // Compiling... // switch-CASE.cpp // c:\_vc\vc--switch-case\vc--switch-case\switch-case.cpp(69) : error C2039: 'numeric_limits' : is not a member of 'std' // c:\_vc\vc--switch-case\vc--switch-case\switch-case.cpp(69) : error C2065: 'numeric_limits' : undeclared identifier // c:\_vc\vc--switch-case\vc--switch-case\switch-case.cpp(69) : error C2275: 'std::streamsize' : illegal use of this type as an expression // c:\_vc\vc--switch-case\vc--switch-case\switch-case.cpp(69) : error C2780: 'const _Ty &std::max(const _Ty &,const _Ty &,_Pr)' : expects 3 arguments - 0 provided // d:\program files\microsoft visual studio 9.0\vc\include\xutility(3390) : see declaration of 'std::max' // c:\_vc\vc--switch-case\vc--switch-case\switch-case.cpp(69) : error C2780: 'const _Ty &std::max(const _Ty &,const _Ty &)' : expects 2 arguments - 0 provided // d:\program files\microsoft visual studio 9.0\vc\include\xutility(3382) : see declaration of 'std::max' // c:\_vc\vc--switch-case\vc--switch-case\switch-case.cpp(141) : error C2039: 'numeric_limits' : is not a member of 'std' // c:\_vc\vc--switch-case\vc--switch-case\switch-case.cpp(141) : error C2065: 'numeric_limits' : undeclared identifier // c:\_vc\vc--switch-case\vc--switch-case\switch-case.cpp(141) : error C2275: 'std::streamsize' : illegal use of this type as an expression // c:\_vc\vc--switch-case\vc--switch-case\switch-case.cpp(141) : error C2780: 'const _Ty &std::max(const _Ty &,const _Ty &,_Pr)' : expects 3 arguments - 0 provided // d:\program files\microsoft visual studio 9.0\vc\include\xutility(3390) : see declaration of 'std::max' // c:\_vc\vc--switch-case\vc--switch-case\switch-case.cpp(141) : error C2780: 'const _Ty &std::max(const _Ty &,const _Ty &)' : expects 2 arguments - 0 provided // d:\program files\microsoft visual studio 9.0\vc\include\xutility(3382) : see declaration of 'std::max' // Build log was saved at "file://c:\_vc\vc--switch-CASE\vc--switch-CASE\Debug\BuildLog.htm" // vc--switch-CASE - 10 error(s), 0 warning(s) // ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========