Problem I Could Really Use Some Guidance (NO PUN INTENDED)

kerlix

Donator
Donator
Joined
Mar 28, 2010
Messages
294
Reaction score
47
Points
43
Basically I'm trying to create what I was describing in
HTML:
https://www.orbiter-forum.com/showthread.php?t=41226
this post.

I was/am using the formulas found here:
HTML:
https://www.orbiter-forum.com/showthread.php?t=34610
.

Unfortunately, I suck at C++. I've spent 2 days trying to learn and I can't get the console program to perform. I'm uploading the code I've written in case anyone is bored and wants to see if they can give me any tips/help.

Luckily, I've commented the daylights out of everything and described what I'm trying to do, and what's actually happening.

It's a rats nest. I admit it. But I couldn't think of anywhere else to ask for help.

If anyone can take a look and either tell me where I'm wrong (I certainly am) or improve it a little, I'd really appreciate it.

I copied it out of VS2019 into Notepad++ and saved it as a .txt file so that it could be attached here.:hailprobe::sos::cry:
 

Attachments

  • FUBAR.txt
    7.6 KB · Views: 8

GLS

Well-known member
Orbiter Contributor
Addon Developer
Joined
Mar 22, 2008
Messages
5,914
Reaction score
2,908
Points
188
Website
github.com
Let me start of with what is probably the best advice in coding: divide and conquer. This is true not only for code writing (use functions/classes/files for specific tasks, instead of one huge function/class/file), but also timewise ("Rome wasn't built in a day", so don't expect to do things overnight).


Looking at the file, right at the top you are mixing "const" with "#define". #define is the "old" C way of defining a constant variable, while const is the safer C++ way, so that's probably the best way to go.
Then you have all the variables declared as global (outside the function), which is not a good thing. Related to that, you are putting the calculations outside of the function, which only works for constant values, e.g.:
Code:
const double PI = 3.1415;
const double PI_2 = PI / 2;// as it has all it needs, the compiler will do this operation during compilation
All the math that takes values that the user inputs, must "run" (be inside the function), so it should be placed after the input, like this:
Code:
int main()
{
	int a;
	int b;
	int c;

	// input the data
	cout << "input 'a': ";
	cin >> a;
	cout << "input 'b': ";
	cin >> b;
	
	// use the data
	c = a + b;

	// output resulting data
	cout << "a + b = : " << c;

	return 0;
}
Start with a small "silly program" like that, play with it and learn, slowly building up.
 

kerlix

Donator
Donator
Joined
Mar 28, 2010
Messages
294
Reaction score
47
Points
43
Thank you. That's a great way to look at it. I was just trying to do too much at one time. Basically drink from a fire hose.

I'll slow down and take it in small steps.

Hopefully I'll get there one day.

Also, don't mind the rambling comments throughout. I was more than burnt out and with quarantine, I was basically venting at VS.

Sent from my PH-1 using Tapatalk
 
Top