My Calculator Program (Multiplication)

Hello everybody, I am new here, and I've been teaching myself how to program in C++ for about 1 1/2 months, so I'm not very good. I just have a quick question about getting the multiplication part of my program to work. The source code is below. Any help would greatly be appreciated.

/*
Copyright: 2009
Author: rmunday214
Date: 10/03/2009
Description: A calculator using loops to do multiple
equations. The type of equation is determined by the
user pressing keys A to E.
*/
#include <cstdio>
#include <stdlib.h>
#include <iostream>
#include <windows.h>
using namespace std;

// The function used to set the color
void setcolor(unsigned short color){
HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hcon,color);
}

// Next number function
// WORKS
int funcNextNumber(int* value){
char inpval[256];
int xx;
cin >> inpval;
if (isalpha(inpval[0])) {
return 0;
}
// Convert letters to integers
xx = atoi(inpval);
*value = xx;
return 1;
}

// Addition Function
// WORKS
int funcAdd(int *answer){
// Loop forever
int accumulator = 0;
int flag = 0;
for(;;){
// Fetch another number
int value = 0;
setcolor (7);
cout << "Enter next number: ";

if (funcNextNumber(&value) == 0){
// If user enters an alphabetical number
// then break from the loop
break;
}

// ...otherwise add the number to the
// accumulator
accumulator = accumulator + value;
flag = 1;
}
*answer = accumulator;
return flag;
}

// Subtraction Function
// WORKS
int funcSub(int *answer){
// Loop forever
int accumulator = 0;
int flag = 0;
for(;;){
// Fetch another number
int value = 0;
setcolor (7);
cout << "Enter next number: ";

if (funcNextNumber(&value) == 0){
// If user enters an alphabetical number
// then break from the loop
break;
}

// ...otherwise subtract the number to the
// accumulator
accumulator = accumulator - value;
flag = 1;
}
*answer = accumulator;
return flag;
}

// Multiplication function
// DOESN'T WORK
int funcMulti(int *answer){
// Loop forever
int accumulator = 0;
int flag = 0;
for(;;){
// Fetch another number
int value = 0;
setcolor (7);
cout << "Enter next number: ";

if (funcNextNumber(&value) == 0){
// If user enters an alphabetical number
// then break from the loop...
break;
}
// WHAT DO I PUT HERE?
}
}

// Division function
int funcDiv(int *answer){
}

int funcSquare(int *answer){
}

int main(){
system("title Calculator");
loop:
system("cls");
setcolor (10);
cout << "Menu\n\n";
setcolor (7);
string choice;
cout << "Please choose from the following: " << endl;
setcolor (10);
cout << "A: Addition\n"
<< "B: Subtraction\n"
<< "C: Multiplication\n"
<< "D: Division\n"
<< "E: Square\n"
<< "F: Menu\n"
<< "G: Quit\n"
<< "\n"
<< endl;
setcolor (7);
cout << "Enter an alphabetical letter to terminate a series\n"
<< "and enter another another letter to terminate the program." << endl;
cin >> choice;
char ch = choice[0];
ch = toupper(ch);
switch (ch){
// Addition
case 'A':
int accumulatedValue;
for(;;){
setcolor (10);
cout << "Enter next sequence" << endl;
if (funcAdd(&accumulatedValue) == 0){
break;
}

cout << "The total is "
<< accumulatedValue
<< "\n"
<< endl;
}

cout << "Thank you" << endl;
break;
// Subtraction
case 'B':
for(;;){
setcolor (10);
cout << "Enter next sequence" << endl;
if (funcSub(&accumulatedValue) == 0){
break;
}

cout << "The total is "
<< accumulatedValue
<< "\n"
<< endl;
}

cout << "Thank you" << endl;
break;
// Multiplication
case 'C':
for(;;){
setcolor (10);
cout << "Enter next sequence" << endl;
if (funcMulti(&accumulatedValue) == 0){
break;
}

cout << "The total is "
<< accumulatedValue
<< "\n"
<< endl;
}
case 'C':
for(;;){
break;
// Division
case 'D':
for(;;){
break;
case 'E':
for(;;){
break;
case 'F':
main();
break;
case 'G':
break;
}

system("PAUSE");
return 0;
}
}
}
}

Topic archived. No new replies allowed.