Skip to content

Instantly share code, notes, and snippets.

@LightningStalker
Last active September 4, 2025 04:56
Show Gist options
  • Select an option

  • Save LightningStalker/48b9c77832698b213c64e6a1d89ccd31 to your computer and use it in GitHub Desktop.

Select an option

Save LightningStalker/48b9c77832698b213c64e6a1d89ccd31 to your computer and use it in GitHub Desktop.
Joules caclulater for capactor of size C being charged to Voltage V
/* Capacitance + Voltage² -> joules calc
* Project Crew™ 6/28/2025
*/
#include <iostream>
#include <cmath>
#include <exception>
using namespace std;
int
main(int argc, char * argv[])
{
long double C, V;
try
{
C = stod(argv[1]);
V = stod(argv[2]);
}catch (...)
{
cerr << "USAGE: $ " << argv[0] << " C(microfarad) V" << endl;
return(EXIT_FAILURE);
}
/* J = ½CV² */
cout << 5e-7 * C * pow(V, 2.0) << endl;
return(EXIT_SUCCESS);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment