Skip to content

Instantly share code, notes, and snippets.

@jamesy0ung
Created November 8, 2024 00:10
Show Gist options
  • Save jamesy0ung/dfbe198325a44f3a39811443300c8c95 to your computer and use it in GitHub Desktop.
Save jamesy0ung/dfbe198325a44f3a39811443300c8c95 to your computer and use it in GitHub Desktop.
#include <iostream>
const int c = { 299792458 };
float findWavelength(float frequency)
{
return(c / (frequency * 1000000)); // Convert MHz to Hz and use meters for wavelength
}
float findDipoleLeg(float wavelength)
{
return((wavelength / 2)/2); // Length of each dipole leg is a quarter of the wavelength
}
int main()
{
double frequency;
std::cout << "Frequency to dipole calculator\n";
std::cout << "Please enter the frequency in MHz : ";
std::cin >> frequency;
if (frequency <= 0) {
std::cout << "Please enter a valid positive frequency.\n";
return 1;
}
std::cout << std::endl;
double wavelength = findWavelength(frequency);
double dipole = findDipoleLeg(wavelength);
std::cout << "The length of each leg is: " << dipole << " meters\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment