#include <iostream> /// my includes
#include <string>
usingnamespace std;
int fnum,snum,answer; char operation; /// Variables
int main(){ ///start of code
cout<<"Please type an operation... +,-,*,/."<<endl; /// Operation input
cin.get(operation);
cout<<"Please enter your first number"<<endl; /// first number input
cin>>fnum;
cout<<"Please enter your second number"<<endl; /// second number input
cin>>snum;
cout<<"processing..."<<"\n"<<endl; /// random (filler)
system("pause");
cout<<"\n\n"<<endl; // skips some lines so it looks cleaner in the consol
switch(operation)
{ /// Switch statement to use the operation at the top
case'+':answer=fnum+snum; break; // addition
case'-':answer=fnum-snum; break; // subtraction
case'*':answer=fnum*snum; break; // multiplication
case'/':answer=fnum/snum; break; // division
}
cout<<"##############"<<endl;
cout<<"# answer #"<<endl;
cout<<fnum<<operation<<snum<<"="<<answer<<endl; /// output/answer with a little box around it
cout<<"# #"<<endl;
cout<<"##############"<<endl;
system("pause");
return 0;
} /// end of code
Please leave suggestions on how i could make it better or fix things.
Apart from the lack of input validation (which I assume you don't care about for this small program), it looks fine. =)
Some suggestions:
1) Don't make variables global. It's a bad habit. Global variables are sloppy. fnum, snum, answer, and operation are all used only inside of main, so that is where they should be defined.
2) Don't be afraid of whitespace. You don't have to cram all the lines so close together. Sometimes putting a few blank lines here and there can make the code easier to read and follow.
3) Some people will tell you that system("pause") is evil. Apart from being non-portable it's a potential security risk. There's like a bazillion topics on this on these boards if you want to read about it.
EDIT:
4) You've got what I got "beginner comments".... your code comments aren't very useful because they're stating the obvious (ie: commenting "addition" on a line that is clearly adding two numbers). This isn't a bad thing... it just kind of exposes your inexperience ;)
It's hard to explain how to comment well. Usually I only try to clarify what I'm doing (apart from general function/class documentation) if the code isn't obvious or if it's part of a larger picture.
@Disch thank you for the advice, one question, do you know how to program games(images for them and such)?
I clicked on this topic, saw that, and I didn't think that he actually directed the question solely at Disch so I thought I would give some advice. That's where it came from.
@Disch thank you for the advice, one question, do you know how to program games(images for them and such)?
Yes.
And FWIW, I would avoid LazyFoo's tutorials, as he teaches SDL 1.x which is horrendously old and outdated. If you must learn SDL, I'd recommend SDL 2.x... though personally I prefer SFML.