|
![]() |
#1 | ||
Join Date: May 2008
Location: Swan River, Canada
Posts: 842
|
![]() Now im not quite sure WHY this isn't working, but on the bolded line, my code finds and error and doesn't want to build
Quote:
__________________
Kugarfang: o hai guiz im trying to find this techno song from the radio and it goes like this: DUN duuuunnnn dudududududun SPLOOSH duuunnnnn We ate the horse. |
||
![]() ![]() |
|
![]() |
#2 | |||
Join Date: Oct 2004
Location: Opole, Poland
Posts: 14,276
|
![]() Your code has a lot of the { } brackets where not neccessary. They're messing up the whole thing.
Further, you're never inputting the value for "dsecondnumber"; Further, whoever you have those comments from... don't trust them on anything relating to programming. EVER. Again. int main(int argc, char* argv[]) is the proper form if you want arguments. int main() if you don't. Do yourself a favor, and replace that ridiculous case with some else if 's. Quote:
Int comes in no less than four subtypes: __int8, __int16, __int32, __int64, and each of those can also be unsigned, for a total of eight types. the usual int is the same as __int32, BTW. There's also the bool type, which can also be used in the same fashion as an integer. There's two types of floating-point values: float and double. Quote:
Unicode chars are stored in two bytes, IIRC, while regular Ascii takes up just one byte (same as __int8) Try incrementing or decrementing a char and see what happens. Char can be unsigned too, BTW. Quote:
__________________
![]() "God. Can't you people see I'm trying to commit a crime against science and nature here?" -- Reed Richards Last edited by The Fifth Horseman; 12-10-2010 at 05:52 PM. |
|||
![]() ![]() |
|
![]() |
#3 | ||
![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Mar 2006
Location: ,
Posts: 4,613
|
![]() Yes, I wonder how you decided to put them. You need to review C syntax.
http://msdn.microsoft.com/en-us/library/66k51h7a.aspx Also, why do you use system() so much? Instead of system("pause") you should use getchar() or similar, so the same thing is done by the program itself, instead of having to call an OS command. And what is the purpose of Code:
system("TITLE Calculator"); system("COLOR 2"); And you should import the header files with the prototypes for the functions you're using.
__________________
Life starts every day anew. Prospects not so good... |
||
![]() ![]() |
|
![]() |
#4 | ||
![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Mar 2006
Location: ,
Posts: 4,613
|
![]() Quote:
Moreover, the reason why you have to put break statements, is because otherwise execution would fall through. BUT this can work in your favour, see this: Code:
switch(cChar) { case '+': cout << "The answer is: " << dfirstnumber << " + " << dsecondnumber << " = " << (dfirstnumber + dsecondnumber) << endl; break; case '-': cout << "The answer is: " << dfirstnumber << " - " << dsecondnumber << " = " << (dfirstnumber - dsecondnumber) << endl; break; /*************/ case '*': case 'x': case 'X': cout << "The answer is: " << dfirstnumber << " X " << dsecondnumber << " = " << (dfirstnumber * dsecondnumber) << endl; break; /*************/ case '/': if(dsecondnumber == 0) cout << "that is an invalid operation" << endl; else cout << "The answer is: " << dfirstnumber << " / " << dsecondnumber << " = " << (dfirstnumber / dsecondnumber) << endl; break; default: cout << "That is an invalid operation" << endl; break; } By the way, you don't need to enclose each case group into brackets. (That defines a scope, which you can do anywhere, if you want variables declared within not to be accessible without.) switch() causes a jump to the matching case, and then execution continues, falling through any intermediate case and default labels, until a break (or return etc.) statement is found. This is special about the switch statement. if (and for, while...) statements do need brackets, if you want more than one statement (line) into them. Above I disposed of the brackets in the if/else, but only because there's only one line for if and another for else. And again a pair of brackets defines a scope, so if you declare a variable within the brackets of an if (or for...) statement, it won't be defined once the program exits the closing bracket. The C/C++ types are not the same across platforms, which is undesirable, but changing it now would break the standard. Depending on the platform, some types may have the same size, for example in 32-bit x86 int and long, or double and long double. Some non-standard extensions (Microsoft etc.) define custom types that are platform-invariant, such as those Horseman mentioned. But there are no subtypes, for example in 32-bit x86 __int32 is equivalent to both int and long; __int16 to short; and __int8 to char. The basic standard types are: char, short, int, long, double, long double. The integers (char, short, int and long) can be unsigned (which doubles their range in absolute value, since the bit usually reserved to keep the sign is saved for another significant binary digit). I don't quite understand the final comments either, let alone the mention of Visual Basic. The name of a variable isn't restricted by its type--simply use self-documenting names that are immediate and intuitive to understand to you and anyone else. Some Visual Basic 6 and earlier coders did like to tag variable names with type prefixes, but that isn't required by the language, its purpose was only making the code more readable.
__________________
Life starts every day anew. Prospects not so good... Last edited by Japo; 13-10-2010 at 04:16 PM. |
||
![]() ![]() |
|
![]() |
#5 | ||
Join Date: Oct 2004
Location: Opole, Poland
Posts: 14,276
|
![]() Quick and dirty fix just to get it working:
Code:
#include <iostream> using namespace std; int main() { system("TITLE Calculator"); system("COLOR 2"); char cChar, cDoagain; // char is a character, its how you get plus and minus signs, etc // double dfirstnumber, dsecondnumber; do { system ("CLS"); cout << "please enter the first number that you would like to use\n"; cin >> firstnumber >> secondnumber; cout << "please enter the operation that you want to complete: (+,-,*, or /)\n"; cin >> cChar; switch (cChar){case '+':{ cout << "The answer is: " << dfirstnumber << " + " << dsecondnumber << " = " << (dfirstnumber + dsecondnumber) << endl; break;} case '-':{ cout << "The answer is: " << dfirstnumber << " - " << dsecondnumber << " = " << (dfirstnumber - dsecondnumber) << endl; break;} case '*':{ cout << "The answer is: " << dfirstnumber << " * " << dsecondnumber << " = " << (dfirstnumber * dsecondnumber) << endl; break;} case 'x':{ cout << "The answer is: " << dfirstnumber << " x " << dsecondnumber << " = " << (dfirstnumber * dsecondnumber) << endl; break;} case 'X':{ cout << "The answer is: " << dfirstnumber << " X " << dsecondnumber << " = " << (dfirstnumber * dsecondnumber) << endl; break;} case '/':{ if(dsecondnumber == 0) cout << "that is an invalid operation" << endl; else cout << "The answer is: " << dfirstnumber << " / " << dsecondnumber << " = " << (dfirstnumber / dsecondnumber) << endl; break;} default:{ cout << "That is an invalid operation" << endl; break; } } cout << "would you like to start again? (y or n)" << endl; cin >> cDoagain; } while (cDoagain == 'Y' || cDoagain == 'y'); system("PAUSE"); }
__________________
![]() "God. Can't you people see I'm trying to commit a crime against science and nature here?" -- Reed Richards Last edited by The Fifth Horseman; 12-10-2010 at 06:17 PM. |
||
![]() ![]() |
|
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Problem with XP | SkiFree | Troubleshooting | 4 | 16-03-2010 02:42 PM |
I Have A Problem! | kevinitzac | General compatibility fixes | 1 | 22-04-2007 03:49 PM |
Problem | Dark Piedone | Tech Corner | 12 | 02-01-2006 07:22 PM |
Dos Box Problem | lost guy | Troubleshooting | 1 | 10-12-2004 09:14 AM |
Dos Problem | Anonymous | Troubleshooting | 13 | 25-09-2004 02:08 AM |
|
|
||
  |