Spoiler: Click to Toggle the Spoiler.
CODE
// Calculator
#include <cstdio>
#include <stdlib.h>
#include <iostream>
using namespace std;
int funcAdd(void){
int accumulator = 0;
for(;;){
int value = 0;
cout << "Enter next number: ";
cin >> value;
if (value < 0){
break;
}
accumulator = accumulator + value;
}
return accumulator;
}
int funcSub(void){
}
int funcMulti(void){
}
int funcDiv(void){
}
int funcSquare(void){
}
int main(int nNumberofArgs, char* pszArgs[]){
string choice;
cout << "Please choose from the following: " << endl;
cout << "A: Addition\n"
<< "B: Subtraction\n"
<< "C: Multiplication\n"
<< "D: Division\n"
<< "E: Square" << endl;
cin >> choice;
char ch = choice[0];
ch = toupper(ch);
switch (ch){
case 'A':
int accumulatedValue;
for(;;){
cout << "Enter next sequence" << endl;
accumulatedValue = funcAdd();
if (accumulatedValue == 0){
break;
}
cout << "The total is "
<< accumulatedValue
<< "\n"
<< endl;
}
cout << "Thank you" << endl;
break;
case 'B':
funcSub();
break;
case 'C':
funcMulti();
break;
case 'D':
funcDiv();
break;
case 'E':
funcSquare();
break;
case 'F':
cout << "Please enter either A, B, C, D, or E." << endl;
break;
}
system("PAUSE");
return 0;
}
#include <cstdio>
#include <stdlib.h>
#include <iostream>
using namespace std;
int funcAdd(void){
int accumulator = 0;
for(;;){
int value = 0;
cout << "Enter next number: ";
cin >> value;
if (value < 0){
break;
}
accumulator = accumulator + value;
}
return accumulator;
}
int funcSub(void){
}
int funcMulti(void){
}
int funcDiv(void){
}
int funcSquare(void){
}
int main(int nNumberofArgs, char* pszArgs[]){
string choice;
cout << "Please choose from the following: " << endl;
cout << "A: Addition\n"
<< "B: Subtraction\n"
<< "C: Multiplication\n"
<< "D: Division\n"
<< "E: Square" << endl;
cin >> choice;
char ch = choice[0];
ch = toupper(ch);
switch (ch){
case 'A':
int accumulatedValue;
for(;;){
cout << "Enter next sequence" << endl;
accumulatedValue = funcAdd();
if (accumulatedValue == 0){
break;
}
cout << "The total is "
<< accumulatedValue
<< "\n"
<< endl;
}
cout << "Thank you" << endl;
break;
case 'B':
funcSub();
break;
case 'C':
funcMulti();
break;
case 'D':
funcDiv();
break;
case 'E':
funcSquare();
break;
case 'F':
cout << "Please enter either A, B, C, D, or E." << endl;
break;
}
system("PAUSE");
return 0;
}
[Close]
