EDIT::: i fixed the problem with the contructor
However, cin automaticly moves to the next line after input. Is there a way i can make Cin stay on the same line, so i can use the +, -, *, and / characters after it? Compile the code and you'll see what i mean.
CODE:
Code:#include <iostream> #include <stdlib.h> class calc { private: long double *num; public: calc(); ~calc(); void getnum(); long double numreturn(){ return *num;} //returns number to print on screen// }; calc::calc() { num = new long double; } calc::~calc() { delete num; } void calc::getnum() { calc(); cin>> *num; } int main(int argc, char *argv[]) { int choose = 0, loop = 0; calc num1, num2;//Instances hold the 2 numbers used in them math// cout<<"Type the number of what you want to do, then press [ENTER]\n\n"; cout<<"1..........Addition\n" //The menu// "2..........Subtraction\n" "3..........Multiplication\n" "4..........Division\n\n" "5..........End Program\n\n\n"; do{ cout<<"What do you want to do? "; cin>>choose; switch(choose) { case 1: { cout<<"Addition\n"; num1.getnum(); cout<<" + "; num2.getnum(); cout<<" = "<<num1.numreturn() + num2.numreturn(); break; } case 2: { cout<<"Subtraction\n"; num1.getnum(); cout<<" - "; num2.getnum(); cout<<" = "<<num1.numreturn() - num2.numreturn(); break; } case 3: { cout<<"Multiplication\n"; num1.getnum(); cout<<" * "; num2.getnum(); cout<<" = "<<num1.numreturn() * num2.numreturn(); break; } case 4: { cout<<"Division\n"; num1.getnum(); cout<<" / "; num2.getnum(); cout<<" = "<<num1.numreturn() / num2.numreturn(); break; } case 5: { cout<<"Program Closing\n\n\n\n"; loop = 1; num1.~calc(); num2.~calc(); break; } default: { cout<<"Not a choice, program returning to Menu\n\n"; break; } } } while(loop == 0); system("PAUSE"); return 0; }



LinkBack URL
About LinkBacks



