Hi there folks!. I have just started to learn C++ (and LOVING every second, I must say!). I have written a very basic VAT calculator; would someone tell me if I have made any obvious mistakes please:
Also - could you explain in LAYMANS terms, what the diff is between:
// This application works out how much VAT you pay, allowing custom VAT rates to be set
#include <iostream>
usingnamespace std;
int main()
{
// declarations here;
float vatrate = 0.0;
float exvat = 0.0;
float total = 0.0;
float totalvat = 0.0;
// Clears screen of any junk
system("clear"); // screen clear for Mac OS X; comment out as applicable, between platforms
// system ("cls"); // screen clear for Win32; comment out as applicable, between platforms
// asks user to set VAT rate
cout << "Please enter VAT rate, in %: ";
// stores VAT rate that user typed
cin >> vatrate;
// asks user to enter the amount - excluding VAT - for which they wish to find the applicable VAT
cout << "Please enter the amount EXCLUDING VAT: ";
// stores ex VAT amount that user typed
cin >> exvat;
// calculates the total, which includes VAT @ rate set by user
total = exvat / 100 * vatrate + exvat;
// calculates the total VAT amount
totalvat = exvat / 100 * vatrate;
// tells user how much they will pay in total, INCLUDING VAT at specified rate
cout << "The total INCLUDING VAT, is: £" << total << "\n\n\n";
// tells user how much VAT they will pay at specified rate
cout << "You are paying £" << totalvat << " VAT, at " << vatrate <<"%\n\n\n";
// <blahblah> general copyleft/right information </blahblah>
cout << "Copyleft, Matt Foot - 6th March 2008\n\n\n";
// system ("pause"); // pauses Win32 console, so app doesn't just exit after completion; comment out for Mac OS X
// App ends
return 0;
}
Finally, having copy/pasted my source DIRECTLY to this webpage from "textmate" (Mac), I see weird characters that have appeared next to my "£" symbol, that are NOT present in my source code. Would you mind telling me why?. Have I set the encoding wrong, in "textmate" editor app?.
#include <iostream>
// #define WIN32
// uncomment above for Win32
#ifdef WIN32
system ("cls");
#else
system ("clear");
#endif
#ifdef WIN32
system ("pause");
#endif
int main ()
........ etc ..........
Never mind - I Googled it; I now realise that these are pre-processor statements. I put the #define <insert definition here> BEFORE int main() and then I insert the #ifdef macros, as and when applicable within the function code, of any particular function.
// This application works out how much VAT you pay, allowing custom VAT rates to be set
#include <iostream>
// #define WIN32
// un-comment the above line, if compiling for WIN32 platform
usingnamespace std;
int main()
{
// declarations here;
float vatrate = 0.0;
float exvat = 0.0;
float total = 0.0;
float totalvat = 0.0;
// Clears screen of any junk - these pre-processor commands look for the #define WIN32 command, and act accordingly
#ifdef WIN32
system ("cls");
#else
system ("clear");
#endif
// asks user to set VAT rate
cout << "Please enter VAT rate, in %: ";
// stores VAT rate that user typed
cin >> vatrate;
// asks user to enter the amount - excluding VAT - for which they wish to find the applicable VAT
cout << "Please enter the amount EXCLUDING VAT: ";
// stores ex VAT amount that user typed
cin >> exvat;
// calculates the total, which includes VAT @ rate set by user
total = exvat / 100 * vatrate + exvat;
// calculates the total VAT amount
totalvat = exvat / 100 * vatrate;
// tells user how much they will pay in total, INCLUDING VAT at specified rate
cout << "The total INCLUDING VAT, is: £" << total << "\n\n\n";
// tells user how much VAT they will pay at specified rate
cout << "You are paying £" << totalvat << " VAT, at " << vatrate <<"%\n\n\n";
// <blahblah> general copyleft/right information </blahblah>
cout << "Copyleft, Matt Foot - 6th March 2008\n\n\n";
// Pauses execution on WIN32. This pre-processor command looks for the #define WIN32 command, and acts accordingly
#ifdef WIN32
system ("pause");
#endif
// App ends
return 0;
}