#include <iostream>
#include <cmath>
usingnamespace std;
int main()
{
char input;
char choice;
double a,b,c,d,e;
for (;;)
{
do
{
cout << "\tCaculator Version- ID 001\n";
cout << "\tThis Will caculate your basics\n";
cout << "\tMy First Program\n";
cout << "Opt. 1 = Addition\n";
cout << "\n"; // produces a blank line
cout << "Opt. 2 = Subtraction\n";
cout << "\n";
cout << "Opt. 3 = Multipulcation\n";
cout << "\n";
cout << "Opt. 4 = Division\n";
cin >> choice;
}
while (choice < '1' || choice > '4' && choice!= '1'); //d ont know
if (choice == 'Q')
system ("CLS");
switch (choice)
{
case'1': // label
cout << "Input the number you want to add.\n";
cin >> a;
cout << "Input the number you want to add 'X' by.\n";
cin >> b;
cout << "Your answer is:\t" << (a)+(b) << "\n";
system ("PAUSE");
system ("CLS");
break;
case'2':
cout << "Input the number you want to subtract.\n";
cin >> a;
cout << "Input the number you want to subtract x by";
cin >> b;
cout << "Your answer is\t" << (a-b) << "\n";
system ("PAUSE");
system ("CLS");
break;
case'3':
cout << "Input the number you want to multiply.\n";
cin >> a;
cout << "Input the number you want to multiply x by.\n";
cin >> b;
cout << "Your answer is:\t" << (a)*(b) << "\n";
system ("PAUSE");
system ("CLS");
break;
case'4':
cout << "Input the number you want to divide.\n";
cin >> a;
cout << "Input the number you want to divide x by.\n";
cin >> b;
cout << "Your answer is:\t" << (a)/(b) << "\n";
system ("PAUSE");
system ("CLS");
break;
case'5':
cout << "Opt. 1 for area of a square" << endl;
cin >> a;
cout << "Opt. 2 for area of a rectangle" << endl;
cin >> (input);
{
if (input == 1)
{ goto asquare;
} elseif (input == 2)
{ goto arectangle;
} elseif (input == false)
{ goto end;
}
asquare:
cout << "Input the mesurement of one side of the square";
cin >> a;
cout << "The area of the square is:\t" << (a) * (a);
system ("PAUSE");
goto end;
arectangle:
cout << "Input the length of the rectangle";
cin a;
cout << "Input the width of the rectangle";
cin b;
cout << "The area of the rectangle is:\t" << (a) * (b);
system ("PAUSE")
goto end;
end:
exit(0)
}
}
return 0;
}
}
}
NEVER use the system ( ) function. Use cin.get ( ) instead of system ( "PAUSE" ), and there are alternative methods to using system ( "CLS" ) that I'll link you to in a bit.
Why the opening bracket at line 82?
At line 102, there should be a semicolon at the end.
At line 105, exit(0) should also have a semicolon.
The last 2 brackets aren't needed.
If you don't mind me asking, where are you learning C++ from?
#include <iostream>
#include <cmath>
usingnamespace std;
#define pi 3.14159265359
#define new '\n'
//line 9 is global: b=base c=base2 l=length w=width r=radius s=side (b&a will be used regular variables
int input; //global
int choice; //global
double b,h,l,r,a,c,s,w,t;//global t=r2
int main()
{
top:
cout << "\tCaculator Version- ID 002" << new;
cout << "\tThis Will caculate your basics" << new;
cout << "\tMy First Program" << new;
cout << "Opt. 1 = Addition" << new;
cout << new;
cout << "Opt. 2 = Subtraction" << new;
cout << new;
cout << "Opt. 3 = Multipulcation" << new;
cout << "\n";
cout << "Opt. 4 = Division" << new;
cout << new;
cout << "Opt. 5 For area" << new;
/*
/\ /\ /\ /\ /\
MAIN MENU ABOVE
*/
cin >> choice ;
{
if (choice == 1)
{ goto a1;
} elseif (choice == 2)
{ goto a2;
} elseif (choice == 3)
{ goto a3;
} elseif (choice == 4)
{ goto a4;
} elseif (choice == 5)
{ goto a5;
}
a1:
cout << "Input the number you want to add." << new;
cin >> a;
cout << "Input the number you want to add 'X' by." << new;
cin >> b;
cout << "Your answer is:\t" << (a)+(b) << new;
system ("PAUSE");
system ("CLS");
goto top;
a2:
cout << "Input the number you want to subtract. " << new;
cin >> a;
cout << "Input the number you want to subtract x by" << new;
cin >> b;
cout << "Your answer is\t" << (a-b) << new;
system ("PAUSE");
system ("CLS");
goto top;
a3:
cout << "Input the number you want to multiply." << new ;
cin >> a;
cout << "Input the number you want to multiply x by. " << new;
cin >> b;
cout << "Your answer is:\t" << (a)*(b) << new;
system ("PAUSE");
system ("CLS");
goto top;
a4:
cout << "Input the number you want to divide. " << new;
cin >> a;
cout << "Input the number you want to divide x by." << new;
cin >> b;
cout << "Your answer is:\t" << (a)/(b) << new;
system ("PAUSE");
system ("CLS");
goto top;
/*
/\ /\ /\ /\ /\ /\ /\ /\
BASIC MATH MENU ABOVE
AREA MENU BELOW
\/ \/ \/ \/ \/ \/ \/
*/
a5:
cout << "Opt. 1 for area of a square" << new;
cout << new;
cout << "Opt. 2 for area of a rectangle" << new;
cin >> (input);
{
if (input == 1)
{ goto asquare;
} elseif (input == 2)
{ goto arectangle;
} elseif (input == 3
{ goto arectangle;
} elseif (input == 4
{ goto arectangle;
} elseif (input == 5
{ goto arectangle;
} elseif (input == 6)
{ goto arectangle;
} elseif (input == 7)
{ goto arectangle;
}
asquare:
cout << "Input the mesurement of one side of the square" << new;
cin >> s;
cout << "The area of the square is:" << (a) * (a) << new;
system ("PAUSE");
system ("CLS");
goto top;
arectangle:
cout << "Input the length of the rectangle" << new;
cin >> a;
cout << "Input the width of the rectangle" << new;
cin >> b;
cout << "The area of the rectangle is:" << (a) * (b) << new;
system ("PAUSE");
system ("CLS");
goto top;
aparallelogram:
cout << "Input the base of the parallelogram" << new;
cin >> b;
cout << "Input the hight of the parallelogram" << new;
cin >> h;
cout << "The area of the parallelogram is:" << (b) * (h) << new;
system ("PAUSE");
system ("CLS");
atrapezoid:
cout << "Input the base of the " << new;
cin >> b;
cout << "Input base 2 of the parallelogram" << new;
cin >> c;
cout << "Input the hight of the parallelogram" << new;
cin >> h;
cout << "The area of the parallelogram is:" << (h/2*(b+c)) << new;
system ("PAUSE");
system ("CLS");
atrapezoid:
cout << "Input the base of the trapezoid" << new;
cin >> b;
cout << "Input base 2 of the trapezoid" << new;
cin >> c;
cout << "Input the hight of the trapezoid" << new;
cin >> h;
cout << "The area of the trapezoid is:" << (h/2*(b+c)) << new;
system ("PAUSE");
system ("CLS");
:acircle
cout << "Input the radius of the circle" << new;
cin >> r;
cout << "The area of the circle is:" << (pi*r*r) << new;
system ("PAUSE");
system ("CLS");
}
}
return 0;
}
umm i fixed it but i need to know how to add more to it like volume, surface area, and im going to add more shapes. my goal is by the end of the year make it do every thing in it can possibly do in algebra...
btw is there a maximum line limit for posting code
#define new '\n'
Whoa whoa whoa, please don't use #define, especially not to define a C++ keyword. For newlines you ought to just use std::endl as in std::cout<<"Hiya world"<<std::endl;
Might you be able to indent the code and get rid of some of the excess spaces? (Specifically, areas like lines 17~20.) Also, I don't think you need a goto top anywhere as you are already in an infinite loop (the for(;;) statement).
oh and how do u calculate exponents ]with user input variables as simple as can be. pref. in a cout statement like i was doing at the top with addition and subtraction
edit Zhuge ill try that but do you really need the std::cout and then the std::endl in the line
I don't get what's wrong with defines. Or is that another thing that's only bad if used incorrectly? Although you're right about not using it with a keyword.
And no, since you have the usingnamespace std; code, you don't need the std::.
Gotos are generally a bad idea. They create what is called "spaghetti code". You should rarely use gotos. I've found only one reason so far to use gotos. In order to get rid of your gotos, you should put the code that you've put under "arectangle:" "atrapezoid:", etc into their own functions, and call those functions in the if statement. This way, the structure of the code is preserved, and it's more readable. Also, it looks like you're missing some parens around lines 99-103.
As for the "top:" goto, you don't need it. Just put the whole thing in a "while(true) {}". Indent & format your code better, it looks very messy. For example, this:
True, but it's not being used correctly. I prefer reading code from said spastic people than someone who uses gotos in place of basic program structure. I've actually had times when a goto was a good solution, but not often.