Capacity Meter

Hallo Dear Community,
I've found here at the bottom of the page, where "Further things to try" is. I tried the 3rd excersise "Average together a group of readings for more accuracy"

Here is a code of what i tried:

/*  RCTiming_capacitance_meter
   *   Paul Badger 2008
   *  Demonstrates use of RC time constants to measure the value of a capacitor 
   * Theory   A capcitor will charge, through a resistor, in one time constant, defined as T seconds where
   *    TC = R * C
   *    TC = time constant period in seconds
   *    R = resistance in ohms
   *    C = capacitance in farads (1 microfarad (ufd) = .0000001 farad = 10^-6 farads ) 
   *    The capacitor's voltage at one time constant is defined as 63.2% of the charging voltage.
   *  Hardware setup:
   *  Test Capacitor between common point and ground (positive side of an electrolytic capacitor  to common)
   *  Test Resistor between chargePin and common point
   *  220 ohm resistor between dischargePin and common point
   *  Wire between common point and analogPin (A/D input)
  #define analogPin      0          // analog pin for measuring capacitor voltage
  #define chargePin      13         // pin to charge the capacitor - connected to one end of the charging resistor
  #define dischargePin   11         // pin to discharge the capacitor
  #define resistorValue  10000.0F   // change this to whatever resistor value you are using
                                    // F formatter tells compliler it's a floating point value
  unsigned long startTime;
  unsigned long elapsedTime;
  float microFarads;                // floating point variable to preserve precision, make calculations
  float nanoFarads;
  int input = 0;                        // contains the user input
  long storage = 0;
  int counter = 0;
  void setup(){
    pinMode(chargePin, OUTPUT);     // set chargePin to output
    pinMode(chargePin, LOW);  
    Serial.begin(9600);             // initialize serial transmission for debugging
  void loop(){
    while(input = 0){
      input = Serial.parseInt();
    digitalWrite(chargePin, HIGH);  // set chargePin HIGH and capacitor charging
    startTime = millis();
    while(analogRead(analogPin) < 648){       // 647 is 63.2% of 1023, which corresponds to full-scale voltage 
    elapsedTime= millis() - startTime;
   // convert milliseconds to seconds ( 10^-3 ) and Farads to microFarads ( 10^6 ),  net 10^3 (1000)  
    while(counter != input){
      microFarads = ((float)elapsedTime / resistorValue) * 1000;   
      storage += microFarads;
    Serial.print(elapsedTime);       // print the value to serial port
    Serial.print(" mS    ");         // print units and carriage return
    microFarads = storage / input;  
    if (microFarads > 1){
      Serial.print((long)microFarads);       // print the value to serial port
      Serial.println(" microFarads");         // print units and carriage return
      // if value is smaller than one microFarad, convert to nanoFarads (10^-9 Farad). 
      // This is  a workaround because Serial.print will not print floats
      nanoFarads = microFarads * 1000.0;      // multiply by 1000 to convert to nanoFarads (10^-9 Farads)
      Serial.print((long)nanoFarads);         // print the value to serial port
      Serial.println(" nanoFarads");          // print units and carriage return
    /* dicharge the capacitor  */
    digitalWrite(chargePin, LOW);             // set charge pin to  LOW 
    pinMode(dischargePin, OUTPUT);            // set discharge pin to output 
    digitalWrite(dischargePin, LOW);          // set discharge pin LOW 
    while(analogRead(analogPin) > 0){         // wait until capacitor is completely discharged
    pinMode(dischargePin, INPUT);            // set discharge pin back to input
    input = 0;

the output of the console:

43802 mS    -1000 nanoFarads
4726 mS    -1000 nanoFarads
4721 mS    -1000 nanoFarads
4717 mS    -1000 nanoFarads
4717 mS    -1000 nanoFarads
4716 mS    -1000 nanoFarads

What i expected:

The programm will take a User Input (an integer) than will start messuring n-times(depends on the User Input) the capacity and will calculate all the n-time messurements together and divide it with the input which the user gave. At the end the calculation should be printed and the input variable should be set to 0 just for the case that nothing gose wrong.

Thanks for reading, hopefully you can giveme answer.

Is this a school assignment? Have you tried inserting print statements to reveal the values of the variables that went into calculating nanoFarads? Start there and work backwards until you find which values are right and which are wrong. It's better than hitting your head against the code to try and see the error (after all, you are the one who made it...).