HeavenCore
Programmer
a simple program that eliminates charachters from a string retaining numeric vlues only to avoid error in a conversion to int. I made this program but it wont work, and i have no idea why, any ideas? any help would be great!?
#include <stdlib.h>
#include <stdio.h>
#include <iostream.h>
int calc(int, int, char);
int main(void)
{char *string = "23"
;
double a, b, answer, quit = 1;
double readyvalue;
char c;
while (quit != 0) {
cout <<"calc"<<endl;
cout <<"enter two numbers"<<endl;
cout <<"First Number: "<<endl;
cin >> string;
readyvalue = atoi(string);
a = readyvalue;
cout<<"Enter opperator: +, -, /, * "<<endl;
cin >> c;
cout <<"Second Number: "<<endl;
cin >> string;
readyvalue = atoi(string);
b = readyvalue;
answer = calc(a, b, c);
cout <<"Your answer is :"<<answer <<endl << "would you like to do another? (0 to quit, 1 to continue)"<<endl;
cin >> quit;
}
return 0;
}
int calc(int a, int b, char c)
{
int answer;
switch (c)
{
case '+' : answer = a + b; break;
case '-' : answer = a - b; break;
case '/' : answer = a / b; break;
case '*' : answer = a * b; break;
default: cout <<"no operator!!" << endl; answer = 0; break;
}
return answer;
}
#include <stdlib.h>
#include <stdio.h>
#include <iostream.h>
int calc(int, int, char);
int main(void)
{char *string = "23"
;
double a, b, answer, quit = 1;
double readyvalue;
char c;
while (quit != 0) {
cout <<"calc"<<endl;
cout <<"enter two numbers"<<endl;
cout <<"First Number: "<<endl;
cin >> string;
readyvalue = atoi(string);
a = readyvalue;
cout<<"Enter opperator: +, -, /, * "<<endl;
cin >> c;
cout <<"Second Number: "<<endl;
cin >> string;
readyvalue = atoi(string);
b = readyvalue;
answer = calc(a, b, c);
cout <<"Your answer is :"<<answer <<endl << "would you like to do another? (0 to quit, 1 to continue)"<<endl;
cin >> quit;
}
return 0;
}
int calc(int a, int b, char c)
{
int answer;
switch (c)
{
case '+' : answer = a + b; break;
case '-' : answer = a - b; break;
case '/' : answer = a / b; break;
case '*' : answer = a * b; break;
default: cout <<"no operator!!" << endl; answer = 0; break;
}
return answer;
}