mardi 15 octobre 2019

Illegal start of type (else)

I'm doing a lab for my CS 110 class and there's one line of code that is not compiling. I made sure that it matched the template on the reference material. I'm not sure how much code you would need to reproduce the problem, so I've provided all of it and //ed where the problem occurs. To be more specific, it's on line 42. And the error says "error: illegal start of type".

I already tried deleting some brackets that I thought were redundant but more errors popped up.

/* Author: Collin Walsh
   Date: 10/15/2019
   File name: NstedIfs.java
*/

import java.util.Scanner;
public class NestedIfs {

   //main
   public static void main(String[] args) {

      Scanner keyboard = new Scanner (System.in);

      double outsideTempF;

      System.out.println("What is the temperature outside? Input a value and press enter ");

         outsideTempF =  keyboard.nextDouble();

      Scanner input = new Scanner (System.in);

         int raining = 0;

      System.out.println("If it is raining, enter the number 1. Then press enter");

         raining = keyboard.nextInt();

      //indicate what clothing to wear, based on temp   
      if (outsideTempF > 70) {
         if (raining == 1) {
            System.outprintln("Wear t-shirt, shorts, sandals, and an unbrella");
         }else{      
            System.out.println("Wear t-shirt, shorts, and sandals.");
        }   
      }else if (outsideTempF <= 30) {
         if (raining == 1)
            System.out.println("Wear boots, pants, raincoat, and gloves.");
         }else{
         //for any temperature beolow 30
            System.out.println("Wear boots, pants, sweater, and gloves.");
         }
      }else{ //this is where the error occurs 
         if (raining == 1) {
           System.out.println("Wear long-sleeve shirt, pants, a raincoat, and shoes");
           }else{
            System.out.println("Wear long-sleeve shirt, pants, and shoes");

      }
   }
}

Aucun commentaire:

Enregistrer un commentaire