   C++ Programming Errors with a Calculator
  Hey everyone. I am programming in C++ with a console application. This is my first time, obviousily. What I want to do is to make it so the user can type in add, minus, divide, multiply. and then the desired operation is selected. If possible can you add more words for the same operation? For add i would want, 1,add,addition etc. How would I go about doing this? Heres my code for the whole project so far. #include <iostream> #include <stdlib.h> using namespace std; int main(int argc, char *argv[]) {  cout <<"Welcome to Compass Calculator v 1.2! In this version you can add and subtract! The best calculator out there, isen't it?" <<endl;  int a = 0; int s = 0;  if (a)  {   cout <<"You have chosen subtraction, now enter two different numbers, the first number must be larger than the second.";   int a = 0;   int b = 0;    cin >> a;   cin >> b;    if (a>b)    {int c = a/b; cout <<"Enter two different numbers of any size, and they will be added together! Now be ready to witness the BEST application you've seen in your LIFE!";    int a = 0;    int b = 0;    cin >> a;   cin >> b;    if (a<b)    {   int c = a+b;cout<< "My fortune cookie reads... "<< c << "!" <<endl;cout <<"Wooo! Good job young grasshoppa'!"<< endl << endl<< "This AWESOME appy provided by CoMpAsS" << endl <<  "Special thanks to Nick Cooper, and Nick Hanna!" << endl <<  "Copyright Compass 2004" <<endl <<endl;    }cout<< "My fortune cookie reads... "<< c << "!" <<endl;cout <<"Wooo! Good job young grasshoppa'!"<< endl << endl<< "This AWESOME appy provided by CoMpAsS" << endl <<  "Special thanks to Nick Cooper, and Nick Hanna!" << endl <<  "Copyright Compass 2004" <<endl <<endl;    }   if (a>b)    {int c = a/b;cout<< "My fortune cookie reads... "<< c << "!" <<endl;cout <<"Wooo! Good job young grasshoppa'!"<< endl << endl<< "This AWESOME appy provided by CoMpAsS" << endl <<  "Special thanks to Nick Cooper, and Nick Hanna!" << endl <<  "Copyright Compass 2004" <<endl <<endl;    }    system("PAUSE");    return 0; }  Edit: Source tagged for Great Justice - Sandman[Edited by - Sandman on July 16, 2004 12:37:33 PM]
  I know the if thing for subtraction is wrong. But how would I do this?   ;  You're using c++ so use c++ headers//this is a c header#include <stdlib.h>//this is the c++ header#include <cstdlib>Quote:I know the if thing for subtraction is wrong. But how would I do this?Here's an example#include <iostream>using namespace std;int add(int a, int b){  return a + b;}int subtract(int a, int b){  return a - b;}int main(int argc, char *argv[]){  char choice; //menu choice  int a, b;   //used for input  do  {    //show menu    cout << "==calculate what?" << endl    << "a) addition" << endl    << "s) subtraction" << endl    << "q) quit" << endl;    cin >> choice;    if(choice == 'a')    { cout << "Enter nubmers to add:" << endl; cin >> a; cin >> b; //output "a + b = answer" cout << a << " + " << b << " = " << add(a, b) << endl;    }    else if(choice == 's')    { cout << "Enter numbers to subtract:" << endl; cin >> a; cin >> b; //output "a - b = answer" cout << a << " - " << b << " = " << subtract(a, b) << endl;    }    else    { //if not q, then invalid choice if(choice != 'q')   cout << "invalid choice!" << endl;    }   }while(choice != 'q'); //continue loop unless input is q return 0;}Doese that code make sense?   ;  Short answer, you read in a string, check to see if it matches one of your commands, and then perform the appropriate function.Any decent book or tutorial should cover basic string handling stuff, I'd recommend you read a bit more of whatever you're learning from.Here's a quick crappy example:int arg1;int arg2;int result;string op;cin >> arg1 >> op >> arg2;if(op == "+"){   result = arg1 + arg2;}else if(op == "-"){   result = arg1 - arg2;}cout << result;;  okay thanks. how do you enter code like that onto these forums?   ;Quote:Original post by OffDaHizzleNokay thanks. how do you enter code like that onto these forums?[ source ] the code [ /source ] . Just remove the spaces.   ;  Okay, thanks! One last quick question, how do I apply an Icon file to an .exe file? I have an icon that I want to replace the white window pic with the blue title bar thingy. How would I go about doing this? I use a PC. I tried searching on the net, but I couldn't figure out how. Will it need to be programmed in the C++ somehow? If so, how?   ;  I'm not sure if I understand your question but if you simply want an icon on the .exe I think you just change it into the properties (right click->change icon) however if you're talking about icons on your window or taskbar ,if I remember correctly, you create your program icon as a resource using the the DevStudio editor (or whatever stuff you have). Your icon should then have a ressource ID (usually you name them) like this one : IDI_ICON1Then you simply have to implement the resource in the windows class when you create it like this I think : WNDCLASSEX wc; //create your window class //...some stuffs herewc.hIcon = LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICON1));//this is where you load your iconwc.hIconSm = LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICON1));//blah blahRegisterClassEx(&wc);//blah blah...I hope this helps you.   ;  Truthfully, I understood 0% of that. :( Can anyone explain more?   ;  Geez...It's not that difficult. Let's say you want to change your internet explorer icon. It's on your desktop right now right ? Right click on it and go to properties. In the properties window you should see a "change icon..." button. That's all there is to it (I think). And for the other part, you can easily see that there are custom icons when you are running a program right ? its the little picture at the top left part of your application window (if you are making a windows application, i'm not talking about console-based stuff). To load your custom icon just create it using an editor and simply load it using the code just above.   