bad operand types for binary operator >=, -, *

后端 未结 4 1104
遥遥无期
遥遥无期 2021-01-29 07:36

I\'m having trouble figuring out how to fix these errors I keep getting for my code

import java.util.Scanner;

public class Unit02Prog1 {

    public static void         


        
4条回答
  •  臣服心动
    2021-01-29 07:53

    your variable numWords is string, please parse it to integer first for comparing. Then, update price to double as well. Sample code is as per below.

        int numWords;
        System.out.print("numWords");
        numWords = input.nextInt();
    
        double price;
    
        if (numWords >= 50) {
            price = ((numWords -50) * .08) + 5.00;
            System.out.println("customer:" + name);
            System.out.println("Placed an ad in catagory:" + catagory);
            System.out.println("Ad length is" + numWords + "words, at a price of $" + price);
        }
    

提交回复
热议问题