help on calculator program
May 3, 2008 at 9:39pm UTC
i'm trying to make a basic calculator in c++ and i wrote a script but i can't seem to find the problem could someone please help me on this one
the full source code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
#include <cstdlib>
#include <iostream>
#include <string>
#include <iomanip>
#include <sstream>
#include <conio.h>
using namespace std;
void calculator () {
int start = 0;
int start2 = 0;
cout<<"_________________________________\n |\n _________________________ |\n | | |\n |" << setw(25) <<start<<"| |\n ------------------------- |\n |\n |\n |\n 1 2 3 |\n |\n |\n 4 5 6 |\n |\n |\n 7 8 9 |\n |\n |\n 0 |\n |\n + - \\ * = |\n |\n_________________________________|\n" ;
int a = 1;
int b = 1;
while (a=b){
char read1[7];
char read2[7];
string numb (read2);
istringstream h (numb);
int number1;
int number2;
int total;
string number (read1);
istringstream g (number);
char sign;
while (read1[start] != '+' && read1[start] != '*' && read1[start] != '-' && read1[start] != '/' ){
if (start != 8){
read1[start] = getch();
g >> number1;
system("cls" );
cout<<"_________________________________\n |\n _________________________ |\n | | |\n |" << setw(25) <<number1<<"| |\n ------------------------- |\n |\n |\n |\n 1 2 3 |\n |\n |\n 4 5 6 |\n |\n |\n 7 8 9 |\n |\n |\n 0 |\n |\n + - \\ * = |\n |\n_________________________________|\n" ;
start++;
}
else if (start == 8){
break ;
}
}
system("cls" );
cout<<"_________________________________\n |\n _________________________ |\n | | |\n |" << setw(25) <<read1[start]<<"| |\n ------------------------- |\n |\n |\n |\n 1 2 3 |\n |\n |\n 4 5 6 |\n |\n |\n 7 8 9 |\n |\n |\n 0 |\n |\n + - \\ * = |\n |\n_________________________________|\n" ;
while (read2[start2] != '+' && read2[start2] != '*' && read2[start2] != '-' && read2[start2] != '/' ){
if (start2 != 8){
read2[start] = getch();
h >> number2;
system("cls" );
cout<<"_________________________________\n |\n _________________________ |\n | | |\n |" << setw(25) <<number1<<"| |\n ------------------------- |\n |\n |\n |\n 1 2 3 |\n |\n |\n 4 5 6 |\n |\n |\n 7 8 9 |\n |\n |\n 0 |\n |\n + - \\ * = |\n |\n_________________________________|\n" ;
start2++;
}
else if (start2 == 8){
break ;
}}
if (read1[start]=='+' ){
total=number1+number2;
}
else if (read1[start] =='-' ){
total=number1-number2;
}
else if (read1[start] =='/' ){
total=number1/number2;
}
else if (read1[start] =='*' ){
total=number1*number2;
}
else {
total=0;
}
system("cls" );
cout<<"_________________________________\n |\n _________________________ |\n | | |\n |" << setw(25) <<total<<"| |\n ------------------------- |\n |\n |\n |\n 1 2 3 |\n |\n |\n 4 5 6 |\n |\n |\n 7 8 9 |\n |\n |\n 0 |\n |\n + - \\ * = |\n |\n_________________________________|\n" ;
}
calculator();
}
int main(int argc, char *argv[])
{
calculator();
system("PAUSE" );
return EXIT_SUCCESS;
}
May 4, 2008 at 8:41am UTC
i started over and rewrote the entire program differently and it works now
Topic archived. No new replies allowed.