2

I am trying to calculate and round up with an IF statement, the code is below. The error comes on the line: if (partterms < 6)

   // Setup Array List for Course CU
        ArrayList<Double> coursecu = new ArrayList<Double>();
  // Read inputs for Course Units and Sum the Value
        System.out.println("Please enter Individual Course CU values, Q to quit:");
        Scanner in2 = new Scanner(System.in);
        while (in.hasNextDouble())
        {
            coursecu.add(in.nextDouble());
        } 
        double sum = 0;
        for(int i = 0; i < coursecu.size(); i++)
        {
            sum = sum + coursecu.get(i);
        }
        System.out.println();
        System.out.println("Total Credit Units Required for Graduation");
        System.out.println(sum);
  // Calculate the Number of Terms to Completion
       {
          double fullterm = sum / planned_units; // Sets Whole Terms 
          double partterm = sum % planned_units; // Sets Partial Terms
        }
        if (partterm < 6)
        {
            number_terms = fullterms++;
        }
        else
        {
            number_terms = fullterms;
        }
Maroun
  • 94,125
  • 30
  • 188
  • 241
rtruelock
  • 31
  • 1
  • 5
    The variable is named `partterm`, not `partterms`. – Jeroen Vannevel Jan 05 '14 at 20:10
  • Thanks Jeroen, I changed it back but it still gives the error. – rtruelock Jan 05 '14 at 20:13
  • 2
    This question appears to be off-topic because it is about a code with a small typo. It will not be useful for anyone else visiting the site. – Sergey Kalinichenko Jan 05 '14 at 20:13
  • Maroun, I am trying to calculate and round up the term number based upon the partterm value. Does that make sense? – rtruelock Jan 05 '14 at 20:14
  • Thanks dasblinkenlight but fixing the typo did not change the error result – rtruelock Jan 05 '14 at 20:15
  • This question was prompted by a problem that is unrelated to the actual question asked. While similar questions may be on-topic here, this one was solved by the asker in a manner unlikely to be relevant to others. This confusion can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting. – Shog9 Jan 05 '14 at 20:41

1 Answers1

5
{ ← 
    double fullterm = sum / planned_units; // Sets Whole Terms 
    double partterm = sum % planned_units; // Sets Partial Terms
} ←

Remove { and } and the variables will be known outside this weird block.

Maroun
  • 94,125
  • 30
  • 188
  • 241