This is the first piece of code I have attempted to write in C++ and need some help getting it to do what I need it to. I am supposed to write a code for a calculator using only pointer and anonymous variables that continuously asks for different operations until the user wants to exit. This is what I have so far and it terminates after asking for the second number. Any help is appreciated, THANK YOU!
Code:
#include<iostream>
#include<cmath>
#include<iomanip>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
int Arithmetic ( int * x , int * y );
int main() {
int num1;
int num2;
cout << "Please enter an integer value:"; // prompts user to enter number
cin >> num1; //stores number
cout << "Please enter a second integer value:"; // prompts user to enter number
cin >> num2; //stores number
Arithmetic( &num1,&num2 );
return 0;
}
int
Arithmetic(int * x, int * y)
{
char * charPtr;
int * intPtr2;
while ( * charPtr != 'q' ){
charPtr = newchar;
cout << "Please select an operation:(+,-,*,/,%) or enter 'q' to exit"; // prompts user to enter and operation or 0 to exit
cin >> *charPtr;
// stores user input
switch ( *charPtr )
{
case'+':
*intPtr2 = *x + *y;
break;
case'-':
*intPtr2 = *x - *y;
break;
case'*':
*intPtr2 = *x * *y;
break;
case'/':
*intPtr2 = *x / *y;
break;
case'%':
*intPtr2 = *x % *y;
break;
default:
cout << "invalid operation, enter 'q' to exit";
break;
}
cout << *intPtr2;
}
return
0;
}