Results 1 to 4 of 4
  1. #1
    LEGiiTxCHAOTiiC's Avatar
    Join Date
    Mar 2011
    Gender
    male
    Location
    Chicago
    Posts
    200
    Reputation
    39
    Thanks
    72

    Fixing Simple Calculator

    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:
    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;
    	}
    }
    If anyone can help, without just doing it for me, I'd appreciate it so much. Any help is greatly appreciated. Thanks in advance!

    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.

  2. #2
    kibbles18's Avatar
    Join Date
    Oct 2008
    Gender
    male
    Location
    US
    Posts
    860
    Reputation
    5
    Thanks
    127
    What's the problem?
    Way she fuckin goes boys

  3. #3
    LEGiiTxCHAOTiiC's Avatar
    Join Date
    Mar 2011
    Gender
    male
    Location
    Chicago
    Posts
    200
    Reputation
    39
    Thanks
    72
    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.

  4. #4
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    /Closed .

Similar Threads

  1. How to Fix Simple Things +Help Resources
    By HomeScillet in forum Combat Arms Help
    Replies: 15
    Last Post: 02-19-2012, 05:12 PM
  2. Simple Calculator W/O Classes
    By Dev_Pump in forum C# Programming
    Replies: 11
    Last Post: 06-11-2010, 09:13 PM
  3. simple charms not working for you??? i have a fix
    By brendyboy in forum Combat Arms Hacks & Cheats
    Replies: 12
    Last Post: 03-06-2009, 09:39 PM
  4. Simple Chams v1.2 Fixed Crash(By Silex)
    By silentrunner2 in forum Combat Arms Europe Hacks
    Replies: 255
    Last Post: 03-03-2009, 08:34 AM
  5. Replies: 208
    Last Post: 03-02-2009, 06:29 PM

Tags for this Thread