code won't compile...with DevC++ but will with VC++

This is a discussion on code won't compile...with DevC++ but will with VC++ within the C++ Programming forums, part of the General Programming Boards category; In my programming class I work with Visual C++ and I made a program that compiles and runs perfectly on ...

  1. #1
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901

    code won't compile...with DevC++ but will with VC++

    In my programming class I work with Visual C++ and I made a program that compiles and runs perfectly on visual C++, but on Dev C++ it doens't recognise things like: left, fixed, right, showpoint. IT sees them as undeclared identifyers and stuff. I e-mailed the guys and they said that not only are those not ANSII standard, but they odn't know what they are used for. Now I got another program similar to this one that is due tomorrow, but I won't be able to test it with DevC++, so that is why I am worried.
    Code:
    #include <iostream>
    #include <fstream>
    #include <iomanip>
    
    using namespace std;
    
    const float propTaxCal = 0.92;
    const float taxRate = 1.05;
    
    int main()
    
    {
    	double assessedVal, taxAmount, propertyTax; 
    
    
    	ofstream outFile;
    	outFile.open("a:ch3_Ex4out.txt");
    	cout << "This Program will help you Calculate property tax\n\n";
    	cout << "Enter the Assesed value of the Property: \n";
    	cin >> assessedVal;
    	cout << "Calculating values to output file on Drive A";
    
    	outFile << fixed <<showpoint << setprecision(2);
    
    	taxAmount = assessedVal * propTaxCal;
    
    	outFile <<left <<"Assesse Value:" <<setw(34) <<setfill('.') <<right <<assessedVal << endl;
    	outFile <<left <<"TaxAmount:"<<setw(38) <<setfill('.') <<right <<taxAmount   << endl;
    	outFile <<left <<"Tax Rate for each $100.00:"<<setw(22) <<setfill('.') <<right <<"1.05"	   << endl;
    	
    	propertyTax = (taxAmount / 100) *  taxRate;
    
    	outFile <<left <<"Property Tax: "  <<setw(34) <<setfill('.') <<right << propertyTax <<endl; 
    
    
    
    	return 0;
    }

  2. #2
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    I need to know what to do because I am almost done with this other prog and won't be able to test it unless I find out how. Sorry for bumping, but I just don't want to be messed up for my class.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    244
    hmm those are all listed at cplusplus.com in the iostream reference section under ios_base.. odd that they don't work in DevC++...

  4. #4
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    I tried adding the .h but that didn't work either

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    244
    Here you go. I looked up fixed, right, and left, and noticed another way of doing it.

    I believe this still does what you want as well:

    Code:
    #include <iostream>
    #include <fstream>
    #include <iomanip>
    
    using namespace std;
    
    const float propTaxCal = 0.92;
    const float taxRate = 1.05;
    
    int main()
    
    {
    	double assessedVal, taxAmount, propertyTax; 
    
    
    	ofstream outFile;
    	outFile.open("a:ch3_Ex4out.txt");
    	cout << "This Program will help you Calculate property tax\n\n";
    	cout << "Enter the Assesed value of the Property: \n";
    	cin >> assessedVal;
    	cout << "Calculating values to    output file on Drive A";
    	outFile.setf(ios::fixed); 
        outFile.setf(ios::showpoint);
        outFile << setprecision(2);
    
    	taxAmount = assessedVal * propTaxCal;
    	outFile.setf(ios::left);
    	outFile << "Assesse Value:" << setw(34) << setfill('.');
    	outFile.setf(ios::right);
        outFile << assessedVal << endl;
        outFile.setf(ios::left);
    	outFile << "TaxAmount:"<< setw(38) << setfill('.');
        outFile.setf(ios::right);
        outFile << taxAmount   << endl;
        outFile.setf(ios::left);
    	outFile << "Tax Rate for each $100.00:"<< setw(22) << setfill('.'); 
        outFile.setf(ios::right);
        outFile << "1.05"	   << endl;
    	
    	propertyTax = (taxAmount / 100) *  taxRate;
    	outFile.setf(ios::left);
    	outFile << "Property Tax: "  << setw(34) << setfill('.');
        outFile.setf(ios::right);
        outFile << propertyTax <<endl; 
    
    
    
    	return 0;
    }
    Too bad its much more tedious (hmm formatting went awry)

  6. #6
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    thankx, that is a lot more work. I also noticed that some things I do on dev don't cross over to VIsual C++, like if you leave .h in, Vis won't compile it. I am going to try to dl the new DevC++ beta, but I proably will just end up doing that. Do you know if that code compiles with Visual C++ also?

  7. #7
    Registered User
    Join Date
    Aug 2001
    Posts
    244
    Originally posted by indigo0086
    thankx, that is a lot more work. I also noticed that some things I do on dev don't cross over to VIsual C++, like if you leave .h in, Vis won't compile it. I am going to try to dl the new DevC++ beta, but I proably will just end up doing that. Do you know if that code compiles with Visual C++ also?
    I was using DevC++ 4 at first then I downloaded the 5 beta just to see if your code would compile on there. It still didn't, so I wrote that up. I think it should compile on VS but I didn't bother to try it.

  8. #8
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    now I am having problems with my current program. It won't recognize strings.
    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    #include <iomanip>
    
    
    using namespace std;
    
    const double fedTaxRate = 0.15;
    const double stateTaxRate = 0.035;
    const double socSecRate = 0.0575;
    const double medicareTaxRate = 0.0275;
    const double pensionPlanRate = 0.05;
    const double healthInsurance = 75;
    
    int main()
    {
         double grossAmount; 
         double fedTax;
         double stateTax;
         double socSecTax;
         double medicareTax;
         double pensionPlan;
         double netPay;
         string employeeName;
         
         ofstream outFile;
         outFile.open ("a:ch3_Ex6out.txt");
         outFile << fixed << setprecision(2);
         cout << "This program will calculate any Taxes and \nyour Net pay based on your gross income.\n\n"
              << "Please Enter your Name - ";
         cin >> employeeName;    
         outFile << employeeName<< "\n";
         
         cout << "Please type in gross amount: $";
         cin >> grossAmount;
         outFile <<setfill('.') <<left << setw(40) << "Gross Amount: " << right << " $" <<grossAmount << "\n";
         
         cout << "Now Calculating Tax Deductions and Net Pay\nresults will be saved as ch3_Ex6out.txt on drive A.";
         
         fedTax = grossAmount * fedTaxRate;
         stateTax = grossAmount * stateTaxRate;
         socSecTax = grossAmount * socSecRate;
         medicareTax = grossAmount * medicareTaxRate;
         pensionPlan = grossAmount * pensionPlanRate;
         netPay = (grossAmount - (fedTax + stateTax + socSecTax + medicareTax + pensionPlan)) - healthInsurance;
         
         outFile <<left << "Federal Tax: " <<setfill('.') << setw(40) << right << " $" << fedTax << "\n";
         outFile <<left << "State Tax: "   <<setfill('.') << setw(40) << right << " $"  << stateTax << "\n";
         outFile <<left << "Social Security Tax: " <<setfill('.') << setw(40) << right << " $"  << socSecTax << "\n";
         outFile <<left << "Medicare/Medicaid Tax: " <<setfill('.') << setw(40) << right << " $" << medicareTax << "\n";
         outFile <<left << "Pension Plan: " <<setfill('.') << setw(40) << right << " $" << pensionPlan << "\n";
         outFile <<left << "Health Insurance: "  <<setfill('.') << setw(40) << right << " $" << healthInsurance << "\n";
         outFile <<left << "Net Pay: " <<setfill('.') << setw(40) << right << " $" << netPay << "\n";
    
         return 0;
    }
    Last edited by indigo0086; 09-25-2002 at 02:42 PM.

  9. #9
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    basically, I am having the problems that I don't have with Visual C++ lol. This sucks, but the program compiles in dev, but the output is rather odd. I compiled the first example in VisC++ and it came out great, and when I compiled it in dev, i had to change so much stuff, then the output was in scientific notation. This sucks

  10. #10
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by indigo0086
    basically, I am having the problems that I don't have with Visual C++ lol. This sucks, but the program compiles in dev, but the output is rather odd. I compiled the first example in VisC++ and it came out great, and when I compiled it in dev, i had to change so much stuff, then the output was in scientific notation. This sucks
    just a word of advice: gcc is god. if something dont work right then either you coded it in a poor/platform specific way, or visc++ was screwing it up. but don't worry, i know going from one compiler to another can make you pull out your hair, but its a very good exercise in increasing the portability of the code you write.
    hello, internet!

  11. #11
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    I downloaded GCC, then deleted it before I had to blow my brains out. Unless someone walks me through instillation from extraction of tar files, I'm not installing it agian.

  12. #12
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >basically, I am having the problems that I don't have with Visual C++ lol.
    Can you be more specific? What string problems are you having exactly?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  13. #13
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by indigo0086
    I downloaded GCC, then deleted it before I had to blow my brains out. Unless someone walks me through instillation from extraction of tar files, I'm not installing it agian.
    quoi? lol what do you think you're using right now?

    hint: devc++ is a gcc-spawn, only easier to install
    hello, internet!

  14. #14
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>outFile.open ("a:ch3_Ex6out.txt");
    You might want to check the value of outFile to ensure the open actually worked. When I ran your code, there was no floppy in the drive, but it still carried on merrily thinking it was doing its job.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  15. #15
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    I am no longer having problems with it, someone was helping me compile it in VisC++ and I got it working in the afternoon. Sorry didn't tell you earlier.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compile Errors in my Code. Can anyone help?
    By DGLaurynP in forum C Programming
    Replies: 1
    Last Post: 10-06-2008, 10:36 AM
  2. Can you create, edit and compile C code with a C++ IDE?
    By nerdpirate in forum C Programming
    Replies: 4
    Last Post: 05-31-2008, 02:54 AM
  3. Visual Studio 2005 - Debug code with compile errors?
    By Swerve in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 03-17-2008, 09:12 AM
  4. I need help to compile this code...
    By wise_ron in forum C Programming
    Replies: 17
    Last Post: 05-07-2006, 01:22 PM
  5. How do they compile code for an OS ?
    By Nutshell in forum A Brief History of Cprogramming.com
    Replies: 49
    Last Post: 03-28-2002, 12:16 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21