It looks like you're new here. If you want to get involved, click one of these buttons!
//Semtex-Primed's Pythagorean theorum calulator v1.00
#include <iostream>
#include <cmath>
int main()
{
double x, y, hyp; //variables
std::cout << \"Semtex-Primed's Pythagorean theorum calulator v1.00\n\" << \"-- You will need the length of the longest side and the shortest side both leading away from the right-angle.\";
std::cout << \"\n\n\"; //blank line output
Again:
//input of longest side
std::cout << \"Enter length of the longest side leading away from the 90-degree angle: \";
std::cin >> x;
if(x <= 0)
{
std::cout << \"Sorry, the inputted number for the longest side cannot be correct, enter a number above 0\" << \"\n\";
goto Again;
}
Again2:
//input of shorter side
std::cout << \"Enter length of the shorter side leading away from the 90-degree angle: \";
std::cin >> y;
if(y <= 0)
{
std::cout << \"Sorry, the inputted number for the shortest side cannot be correct, enter a number above 0\" << \"\n\";
goto Again2;
}
//calculation area
hyp = sqrt(x*x + y*y);
//answer being outputted.
std::cout << \"The length of your Hypotenuse is: \" << hyp;
return 0;
}
// Testing Void main.cpp : Defines the entry point for the console application.
//
//Semtex-Primed's Pythagorean theorum calulator v1.00
#include <iostream>
#include <cmath>
double firstside(double x); //telling the compiler to look elsewhere in the code for the functions
double secondside(double y, double x);
double calculation(double x, double y);
int main(void)
{
static double x, y, hyp; //variables. I forgot if I needed static or not o.
std::cout << \"Semtex-Primed's Pythagorean theorum calulator v1.00, with a coupla changes from CtrlAltxGhostx\n\n\" << \"-- You will need the length of the longest side and the shortest side both leading away from the right-angle.\n\n\";
while(1) //Beginning of While loop
{ // While loop block inside curly braces
x = firstside(x); //Using the function..
y = secondside(y, x);//\"
hyp = calculation(x, y);//\"
//answer being outputted.
std::cout << \"The length of your Hypotenuse is: \" << hyp;
//pause
std::cout << \"\nPress <enter> to continue...\" << std:: endl;
std::cin.sync();
std::cin.get();
//end of pause
}//end of While loop
}
double firstside(double x)
{
//input of longest side
std::cout << \"Enter length of the longest side leading away from the 90-degree angle: \";
std::cin >> x;
if(x <= 0) //error checking
{
std::cout << \"Sorry, the inputted number for the longest side cannot be correct, enter a number above 0\" << \"\n\";
firstside(x); //recall of the function - replaces goto
}
return(x); //return the value
}
double secondside(double y, double x)
{
//input of shorter side
std::cout << \"Enter length of the shorter side leading away from the 90-degree angle: \";
std::cin >> y;
if(y <= 0 || y >= x) //error checking. It also checks to see if the value is larger than x.
{
std::cout << \"Sorry, the inputted number for the shorter side cannot be correct, enter a number above 0\" << \"\n\";
secondside(y, x);//recall of the function - replaces goto
}
return(y);//return the value
}
double calculation(double x, double y){return(sqrt(x*x + y*y));} //one line calculatory functions are nice :)
Goto's are bad practice.
On HF, they led me to 2/3 pages of flaming. I suggest you switch it with a While loop, and returning functions.
// Testing Void main.cpp : Defines the entry point for the console application.
//
//Semtex-Primed's Pythagorean theorum calulator v1.00
#include <iostream>
#include <cmath>
double firstside(double x); //telling the compiler to look elsewhere in the code for the functions
double secondside(double y, double x);
double calculation(double x, double y);
int main(void)
{
static double x, y, hyp; //variables. I forgot if I needed static or not o.
std::cout << \"Semtex-Primed's Pythagorean theorum calulator v1.00, with a coupla changes from CtrlAltxGhostx\n\n\" << \"-- You will need the length of the longest side and the shortest side both leading away from the right-angle.\n\n\";
while(1) //Beginning of While loop
{ // While loop block inside curly braces
x = firstside(x); //Using the function..
y = secondside(y, x);//\"
hyp = calculation(x, y);//\"
//answer being outputted.
std::cout << \"The length of your Hypotenuse is: \" << hyp;
//pause
std::cout << \"\nPress <enter> to continue...\" << std:: endl;
std::cin.sync();
std::cin.get();
//end of pause
}//end of While loop
}
double firstside(double x)
{
//input of longest side
std::cout << \"Enter length of the longest side leading away from the 90-degree angle: \";
std::cin >> x;
if(x <= 0) //error checking
{
std::cout << \"Sorry, the inputted number for the longest side cannot be correct, enter a number above 0\" << \"\n\";
firstside(x); //recall of the function - replaces goto
}
return(x); //return the value
}
double secondside(double y, double x)
{
//input of shorter side
std::cout << \"Enter length of the shorter side leading away from the 90-degree angle: \";
std::cin >> y;
if(y <= 0 || y >= x) //error checking. It also checks to see if the value is larger than x.
{
std::cout << \"Sorry, the inputted number for the shorter side cannot be correct, enter a number above 0\" << \"\n\";
secondside(y, x);//recall of the function - replaces goto
}
return(y);//return the value
}
double calculation(double x, double y){return(sqrt(x*x + y*y));} //one line calculatory functions are nice :)
I personally have no problem with goto, but it IS better to use While and functions.
Look at my code - It is good to practice function and loop usage.
Apart from that, good for a beginner's program :)
Off Topic: HQ first post ftw?
[spoiler=LOL] Actually I thought you might bring that particular person up. I actually read the thread your talking about earlier I think the argument being whether it meets the 'standard' or not and not whether it compiles. He's a good coder, his knowledge shows through sometimes, however his methods and general arrogance is beyond belief and clouds the issue. He likes being the person who spots an error and rips the person to bits, if he thinks your prone to making school-boy errors he'll follow you about. I've heard it said a few times he's done the same, thread stalking that is.[/spoiler]
I'm all for people helping and I'll be the last person to turn down advice/help in C++ (as anyone who's learned it will surely appreciate). It's a big learning curve, especially with little to no background in coding. I'll be learning alot more detail on c++/c at University next year so hopefully i'll be able to get shot of vb.net full stop lol (once i've finished my RAT that is).
However, my confusion generally ensues from VC++ not enforcing the standard.
VC++ doesn't care about int main() etc., so I have Code::Blocks now, and NetBeans if I can be bothered to set it up.
However, the whole thread could have been avoided if he had just gone "Actually, you should be using 'int main(void)'" or something along those lines.