#include <iostream>
usingnamespace std;
class setup{
public:
void title(){
cout << "hello!!!, IM A CALCULATOR... lets get started" << endl << endl;
}
};
int main()
{
setup setapp1;
setapp1.title();
system("TITLE calculator");
system("color 2");
double a;
double b;
char cchar;
char cagain;
do{
cout << "please enter the first number you want to use" << endl;
cin >> a;
cout << "please enter the operation you would like to use" << endl;
cin >> cchar;
cout << "please enter the second number you would like to use" << endl;
cin >> b;
switch (cchar){
case'+':
cout << "the answer is: " << a << " + " << b << " = "
<< (a + b) << endl;
break;
case'-':
cout << "the answer is: " << a << " - " << b << " = "
<< (a - b) << endl;
break;
case'*':
cout << "the answer is: " << a << " * " << b << " = "
<< (a * b) << endl;
break;
case'/':
cout << "the answer is: " << a << " / " << b << " = "
<< (a / b) << endl;
break;
default:
cout << "you cant use that operation";
break;
}
cout << "would you like to start again (y or n)";
cin >> cagain;
}while (cagain == 'y' || cagain == 'Y');
system("pause");
return 0;
}
What those two lines are doing are creating a setup object, and then accessing its title function. Just like strings are objects, so is setup, so saying
string setapp1;
would create a string object, just like
setup setapp1;
creates a setup object.
Accessing a member function is like accessing a regular function, except it's particular to a certain class. typing in the name of an instance of an object (in this case, setapp1), a '.' (dot), and the name of the function (in this case, title()), will make the code jump to the function up there, and do whatever it says to do.
ok thanks and is there any way to let the user enter any amounts of numbers he wants to use. for example on this program you can only enter two numbers but is there i way i can like let them choose how many numbers they want to add?
#include <iostream>
usingnamespace std;
class setup{
public:
void title(){
cout << "hello!!!, IM A CALCULATOR... lets get started" << endl << endl;
}
};
int main()
{
setup setapp1;
setapp1.title();
system("TITLE calculator");
system("color 2");
double a;
double b;
char cchar;
char cagain;
do{
cout << "please enter the first number you want to use" << endl;
cin >> a;
cout << "please enter the operation you would like to use" << endl;
cin >> cchar;
cout << "please enter the second number you would like to use" << endl;
cin >> b;
switch (cchar){
case'+':
cout << "the answer is: " << a << " + " << b << " = "
<< (a + b) << endl;
break;
case'-':
cout << "the answer is: " << a << " - " << b << " = "
<< (a - b) << endl;
break;
case'*':
cout << "the answer is: " << a << " * " << b << " = "
<< (a * b) << endl;
break;
case'/':
cout << "the answer is: " << a << " / " << b << " = "
<< (a / b) << endl;
break;
default:
cout << "you cant use that operation";
break;
}
cout << "would you like to start again (y or n)";
cin >> cagain;
}while (cagain == 'y' || cagain == 'Y');
system("pause");
return 0;
}
is there i way i can like let them choose how many numbers they want to add?
Ask them how many numbers they want to add, and then loop that many times, getting a number each time. I refuse to believe you couldn't think of that yourself.
also in the function"void title" is there a way i can only make the program show what that function says and make it say press enter to continue and then make "hello!!!, IM A CALCULATOR... lets get started" go away and continue with the program