What's the problem?
Ok, I know almost nothing about C++, so I was wondering if anyone could assist me in fixing my simple learning base program. I mean not to disturb more skilled programmers with my lack of knowledge, but to gain more knowledge of my own.
My current program is just a simple input output command window calculator.
Ok, so my code follows as shown:
If anyone can help, without just doing it for me, I'd appreciate it so much. Any help is greatly appreciated. Thanks in advance!Code:#include "stdafx.h" #include <iostream> #include "conio.h" //using namespace std; float num1; // first integer float num2; // second integer int add; // addition [+] int sub; // subtraction [-] int mul; // multiplication[*] int quo; // answer to division [/] int sum; // answer to addition [+] int difference; // answer to subtraction [-] int product; // answer to multiplication[*] // = int method; // method e.g. ( +, -, *, / ) int _tmain(int argc, _TCHAR* argv[]) { std::cout << "Enter first integer/float: " << std::endl; std::cin >> num1; std::cout << "Enter second integer/float value: " << std::endl; std::cin >> num2; std::cout << "Enter method ( +, -, *, / )" << std::endl; std::cin >> method; if(method == '+') { sum = num1 + num2; std::cout << sum << std::endl; } else if(method == '-') { difference = num1 - num2; std::cout << difference << std::endl; } else if(method == '*') { product = num1 * num2; std::cout << product << std::endl; } else if(method == '=') { quo = num1 / num2; std::cout << quo << std::endl; } else { std::cout << "Unknown function, please use [ +, -, *, / ]" << std::cout; } }
When I say almost no knowledge of C++, I didn't mean I copied this code, I know Java and am trying to learn C languages now, I am not a code leech so please don't assume I ripped this code off.
Last edited by LEGiiTxCHAOTiiC; 02-01-2012 at 04:00 PM.
What's the problem?
Way she fuckin goes boys
When I execute the program, I can enter the two float/integer numbers, but when the program asks for the method e.g. add, subtract etc. And I enter + or add, it closes without considering the if, else if or printing the result (in my code as sum, difference, quo, product).
---------- Post added at 06:07 PM ---------- Previous post was at 06:03 PM ----------
Updated code:
Code:#include "stdafx.h" #include <iostream> #include "conio.h" //using namespace std; // num1 int num1; // first int // num2 int num2; // second int // methods int add; // addition [+] int sub; // subtraction [-] int mul; // multiplication[*] int divi; // division [/] // result types int quo; // answer to division [/] int sum; // answer to addition [+] int difference; // answer to subtraction [-] int product; // answer to multiplication[*] int method; // method e.g. ( +, -, *, / ) int _tmain(int argc, _TCHAR* argv[]) { std::cout << "Enter first integer/float: " << std::endl; std::cin >> num1; std::cout << "Enter second integer/float value: " << std::endl; std::cin >> num2; std::cout << "Enter method ( +, -, *, / )" << std::endl; std::cin >> method; if(method == add) { sum = num1 + num2; std::cout << sum << std::endl; } else if(method == sub) { difference = num1 - num2; std::cout << difference << std::endl; } else if(method == mul) { product = num1 * num2; std::cout << product << std::endl; } else if(method == divi) { quo = num1 / num2; std::cout << quo << std::endl; } else { std::cout << "Unknown function, please use [ +, -, *, / ]" << std::cout; } }
---------- Post added at 06:20 PM ---------- Previous post was at 06:07 PM ----------
Ok, I fixed the code, sorry for wasting time, I messed with it a little and got it work fine on VC++.net
/req close
Last edited by LEGiiTxCHAOTiiC; 02-01-2012 at 04:11 PM.