Well a while ago i started learning C. Then i toook about a month off from learning anything new, or even using what i already had learnt. I came back the other day to get goin again with it and i couldnt remember how to do anything. Well i gave up on C and yesterday i started learning C++. I relearned what i new very quik and i made my first Calculator program just a little bit ago. Heres the code in all its glory.
Code:
#include <iostream> //Matt's New calculator program in C++ :)
#include <stdlib.h> //It works too =D
float add(float a, float b);
float sub(float a, float b);
float mult(float a, float b);
float div(float a, float b);
float a, b;
int main(int argc, char *argv[])
{ int choose;
int l;
for(int l=0; l<10000; a++)
{
cout<<"\n WELCOME";
cout<<"\n\n\n1. Addition";
cout<<"\n\n2. Subtraction";
cout<<"\n\n3. Multiplication";
cout<<"\n\n4. Division\n\n";
cout<<"Pick the number of what you want to do, then press enter\n\n";
cin>>choose;
switch (choose)
{
case 1:
{
add(a, b);
break;
}
case 2:
{
sub(a, b);
break;
}
case 3:
{
mult(a, b);
break;
}
case 4:
{
div(a, b);
break;
}
default:
{
cout<<"Not recognized as a choice, program will quit\n";
}
}
system("PAUSE");
}
return 0;
}
float add(float a, float b)
{
cout<<"You have chosen to add\n";
cout<<"Input 2 numbers you wish to add\n";
cin>>a>>b;
cout<<a<<" + "<<b<<" = "<< a+b;
}
float sub(float a, float b)
{
cout<<"You have chosen to subtract\n";
cout<<"Input 2 numbers you wish to subtract.\n(The first number will be subtracted by the second)\n";
cin>>a>>b;
cout<<a<<" - "<<b<<" = "<< a-b;
}
float mult(float a, float b)
{
cout<<"You have chosen to multiply\n";
cout<<"Input 2 numbers that you wish to multiply\n";
cin>>a>>b;
cout<<a<<" x "<<b<<" = "<< a*b;
}
float div(float a, float b)
{
cout<<"You have chosen to divide\n";
cout<<"Input 2 numbers that you wish to divide. \n(The first number will be divided by the second)\n";
cin>>a>>b;
cout<<a<<" / "<<b<<" = "<< a/b;
}
This is big for me because i did it without any big errors that i got stuck on, or any help. Let me know if im doing something wrong that could be done alot easier some other way. Thanks.