/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: main.cpp
* Author: alessandrobarazzuol
*
* Created on 1 febbraio 2020, 19.46
*/
#include <cstdlib>
#include<iostream>
#include <stdlib.h>
using namespace std;
int meno(int a,int b)
{
return a-b;
}
int piu(int a, int b)
{
return a+b;
}
int diviso(int a,int b)
{
if(b!=0)
return a/b;
else
exit(1);
}
int per(int a, int b)
{
return a*b;
}
char op(int a)
{
switch(a)
{
case 1:
return '+';
case 2:
return '-';
case 3:
return '*';
case 4:
return '\\';
}
}
using namespace std;
/*
*
*/
int main(int argc, char** argv) {
int (*calcolatrice[4])(int,int) ={piu,meno,per,diviso};
int scelta,a,b;
do
{
cout<<"\n1. +\n2. -\n3. *\n4. \\\n";
cin>>scelta;
cout<<"a= ";
cin>>a;
cout<<"b= ";
cin>>b;
cout<<a<<op(scelta)<<b<<" = ";
switch(scelta)
{
case 1:
cout<<calcolatrice[0](a,b);
break;
case 2:
cout<<calcolatrice[1](a,b);
break;
case 3:
cout<<calcolatrice[2](a,b);
break;
case 4:
cout<<calcolatrice[3](a,b);
break;
}
system("clear");
} while(1);
return 0;
}
Post Views: 5.654