Code for pressing a button

0 Miguel Bastos · April 20, 2015
Hey

I'm a newbie at programming so i started learning it on the internet and I'm trying to improve my skills , but i've got a problem that is , i want to make a calculator , i decided that my calculator will only have 3 operations , + ; - ; * .

I want to open the console and it will give me a message about what kind of operation i want to do , addition , subtraction or multiplication.

There is the problem , i cant define a rule that if i press the F1 key it will stand for the addition operation , if i press the F2 it will stand the subtraction , and if i press F3 it will stand for multiplication.

I'm saying F1 , F2, F3 but it can be any Key like a , b ,c whatever

I'll let here my code 


#include

using namespace std;

int F1(int x, int y)
{
cout  x;
cout  y;

int answer = x + y;


return answer;
}

int F2 (int z, int c)
{
cout  z;
cout  c;

int minusanswer = z - c;

return minusanswer;

}


int F3 (int v, int b)
{
cout  v;
cout  b;

int multipanswer = v * b;

return multipanswer;

}

Post a Reply

Replies

Oldest  Newest  Rating
0 Miguel Bastos · April 20, 2015
I couldn upload all the code i don't know why  , same thing can't upload all the code here too..

#include

using namespace std;

int F1(int x, int y)
{
cout  x;
cout  y;

int answer = x + y;


return answer;
}

int F2 (int z, int c)
{
cout  z;
cout  c;

int minusanswer = z - c;

return minusanswer;

}


int F3 (int v, int b)
{
cout  v;
cout  b;

int multipanswer = v * b;

return multipanswer;

}

int main()
{
cout
0 ♦Avishka RJ ♦™ · April 20, 2015
just checkout below site.use that ascii code with IF statements.

http://www.thecodingforums.com/threads/re-ascii-code-for-functions-keys-f1-f12-and-tab-key.277457/
0 ♦Avishka RJ ♦™ · April 20, 2015
if you need to post full code just use "insert a quote" option I also feel there's a proble in "code"  
0 Miguel Bastos · April 20, 2015
Thank you i will post here , it is just a few lines but is essencial.


#include <iostream>

using namespace std;

int F1(int x, int y)
{
cout << "Enter a number: " << endl;
cin >> x;
cout << "Enter a number: " << endl;
cin >> y;

int answer = x + y;


return answer;
}

int F2 (int z, int c)
{
cout << "Enter a number: " << endl;
cin >> z;
cout << "Enter a number: " << endl;
cin >> c;

int minusanswer = z - c;

return minusanswer;

}

int F3 (int v, int b)
{
cout << "Enter a number: " << endl;
cin >> v;
cout << "Enter a number: " << endl;
cin >> b;

int multipanswer = v * b;

return multipanswer;

}

int main()
{
cout << "What Type of calculation do you wanna make? " << endl;
cout << "F1--> addition   " << "   F2-->subtraction   " << "   F3-->multiplication" << endl;


if (F1)

F1(1, 1);

else if (F2)

F2(2, 2);


else if (F3)

F3(2, 2);


return 0;
}

0 ♦Avishka RJ ♦™ · April 24, 2015


#include <iostream>
using namespace std;

double answer;

void addition(double x,double y);
void subst(double x,double y);
void multiplication(double x,double y);
void division(double x,double y);


int main(){

    double num1,num2;
    char operater;
    cout<<"Enter a number"<<endl;
    cin >> num1;
    cout<<"Enter a number"<<endl;
    cin>>num2;
    cout<<"Press + for Addition"<<endl;
    cout<<"Press - for Substraction"<<endl;
    cout<<"Press * for Multiplication"<<endl;
    cout<<"Press / for Division"<<endl;
    cin>>operater;

    if(operater==43){
        addition(num1,num2);
    }
    else if(operater==45){
        subst(num1,num2);
    }
    else if(operater==42){
        multiplication(num1,num2);
    }
    else if(operater==47){
        division(num1,num2);
    }
    else{
        cout<<"Invalid operater"<<endl;
        return -1;
    }
    return 0;
}

void addition(double x,double y){
    answer = x+y;
    cout<<"Answer is "<<answer;
}

void subst(double x,double y){
    answer = x-y;
    cout<<"Answer is "<<answer;
}

void multiplication(double x,double y){
    answer = x*y;
    cout<<"Answer is "<<answer;
}

void division(double x,double y){
    answer = x/y;
    cout<<"Answer is "<<answer;
}

+1 ♦Avishka RJ ♦™ · April 24, 2015
/images/forum/upload/2015-04-24/f43ebd60415542469b23c732bec6df47.png
+1 ♦Avishka RJ ♦™ · April 24, 2015
For more info::

http://www.softwareandfinance.com/Turbo_C/bioskey.html
  • 1

C++

107,038 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator