So currently I am still confused in using pointers and reference and I do not know if what I am doing is right. My program is a calculator that stores everything the user inputs. There is an option that the user will be asked if he/she want to view the history and if he/she wants it the program will show all the data he/she inputs.And I need to use pointers and reference in my program but I am still confused on how to use pointers and reference into array Here is my initialization:
int main() {
int size = 1, fNum[size], sNum[size];
char oprtn[size], answer;
;
float result[size];
int *ptrf = &fNum[size];
int *ptrs = &sNum[size];
char *ptro = &oprtn[size];
float *ptrRes = &result[size];
while (true) {
cout << "=====CALCULATOR=====\n\n";
cout << "ENTER TWO NUMBERS:" << endl;
while (!(cin >> *ptrf >> *ptrs)) {
system("cls");
cout << "INVALID INPUT. PLEASE ENTER TWO NUMBERS:\n";
cin.clear();
cin.ignore(2);
}
cout << endl;
do {
cout << "Choose Operation to be Used: \n"
<< " + --- Addition \n"
<< " - --- Subtraction \n"
<< " * --- Multiplication \n"
<< " / --- Division \n"
<< " % --- Remainder \n";
cout << "Answer: ";
cin >> answer;
cout << endl;
switch (answer) {
case '+':
cout << "ADDITION\n";
break;
case '-':
cout << "SUBTRACTION\n";
break;
case '*':
cout << "MULTIPLICATION\n";
break;
case '/':
cout << "DIVISION\n";
break;
case '%':
cout << "REMAINDER\n";
break;
default:
answer = false;
system("cls");
cout << "PLEASE ENTER A VALID ANSWER. CHOOSE BELOW.\n\n";
cout << "FIRST NUMBER: " << *ptrf << endl;
cout << "SECOND NUMBER: " << *ptrs;
cout << endl << endl;
continue;
}
} while (!answer);
cout << "DO YOU WANT TO TRY AGAIN? (Y / N): ";
cin >> answer;
switch (answer) {
case 'Y':
case 'y':
system("cls");
continue;
default:
cout << "VIEW HISTORY? (Y / N): ";
cin >> answer;
switch (answer) {
case 'Y':
case 'y':
cout << "HISTORY\n\n";
break;
default:
return 0;
}
}
}
}
sizeis1so all your arrays are really just a single numbersize(I dont see it in the code) but that wont change the size of the arrays. They are still arrays of size 1std::vectorinstead.