learning C++ and electronics: simple program to calculate Charge (I avg) and number of electrons per given unit of time through copper
/*Date: Feb 28, 2016
**Author: A L
**Purpose: This programs takes in Amps and time and returns the
** number of electrons passing through a specific time
** and the current (C) or 1A = 1C\s
** based on information from:
**Scherz, P., & Monk, S. (2013). Practical electronics for inventors (3rd ed.). McGraw-Hill.
**
*/
#include <iostream>
#include <math.h>
int main()
{
//init variables
float copper = 0.0;
float timeInSec = 0.0;
float amps = 0.0;
float charge = 0.0;
float numOfElectrons = 0.0;
//assignments
copper = 1.602 * powf(10.0, -19.0);
//get user input
cout << "This programs takes in Amps and time and returns the";
cout << "\nnumber of electrons passing through a specific time";
cout << "\nand the current (C) or 1A = 1C\\s." << endl;
cout << "\nPlease enter the amount of current in amps(A)(eg. 2):";
cin >> amps;
cout << "\nPlease enter the time in seconds (eg. 2):";
cin >> timeInSec;
//calculations
charge = amps * timeInSec;
numOfElectrons = charge / copper;
cout << endl << "\nThe charge that passes a given point in " << timeInSec << " seconds is: " << charge << "C";
cout << "\n The number of electrons passing through with a charge of " << charge << "C" << " is " << numOfElectrons;