import java.util.Scanner;
public class Ct{
public static void mian(String args[]){
System.out.println("请输入产品的编号和销量");
Scanner input=new Scanner(System.in);
  int num=input.nextInt();
  int sales=input.nextInt();
  while(num!=0){
   switch(num){
   case 1:{ double a=2.98*sales;
   System.out.printf("the salemoney of product 1 is%f\n",+a);
   }break;
   case 2:{ double b=4.50*sales;
   System.out.printf("the salemoney of product 2 is%f\n",+b);
   }break;
   case 3:{ double c=9.98*sales;
   System.out.printf("the salemoney of product 3 is%f\n",+c);
   }break;
   case 4:{ double d=4.49*sales;
   System.out.printf("the salemoney of product 4 is%f\n",+d);
   }break;
   case 5:{ double e=6.87*sales;
   System.out.printf("the salemoney of product 5 is%f\n",+e);
   }break;
   default:{System.out.println("你输入了一个错误的产品编号");
   }break;
  
     } System.out.println("请输入0计算总和或继续输入产品编号");
    
      num=input.nextInt();
  
  }  
       while(num=0){ double total=a+b+c+d+e;
         }
     
     
     
     System.out.printf("The total salemoney of product is %f\n",+total);
}
}
这行while(num=0){ double total=a+b+c+d+e;
         }
 为什么会出现说找不到符号啊,不兼容的符号呢??是不是我的变量已经超出了作用域了??我的程序是想实现输入一个num让它计算,等到用户输完数据就跳出上面的第一个while然后计算total并打印

解决方案 »

  1.   

    while(num=0)
    num=0是一个赋值语句,不能作为条件判断。用num==0
      

  2.   

    另外你这种情况,switch的case里面用不着加{},本身带了break就是一个程序块。
    楼主是用c的吧?还在用printf
      

  3.   


    没看清啊,sorry,你的第一while里面的double a,b,c都移到while前面去,变量作用域问题。
      

  4.   

    = is assignment operator
    == is one of the comparative operators
      

  5.   

    int sales=input.nextInt();
    这行下面:
    double a,b,c,d,e,total;
    下面的所有double都去掉!
      

  6.   


    import java.util.Scanner;public class Ct {
    public static void main(String args[]) {
    System.out.println("请输入产品的编号和销量");
    Scanner input = new Scanner(System.in);
    int num = input.nextInt();
    int sales = input.nextInt();
    double a = 0, b = 0, c = 0, d = 0, e = 0, total = 0;
    while (num != 0) {
    switch (num) {
    case 1:
    a = 2.98 * sales;
    System.out.println("the salemoney of product 1 is%f\n" + a);
    break;
    case 2:
    b = 4.50 * sales;
    System.out.println("the salemoney of product 2 is%f\n" + b);
    break;
    case 3:
    c = 9.98 * sales;
    System.out.println("the salemoney of product 3 is%f\n" + c);
    break;
    case 4:
    d = 4.49 * sales;
    System.out.println("the salemoney of product 4 is%f\n" + d);
    break;
    case 5:
    e = 6.87 * sales;
    System.out.println("the salemoney of product 5 is%f\n" + e);
    break;
    default:
    System.out.println("你输入了一个错误的产品编号");
    }
    System.out.println("请输入0计算总和或继续输入产品编号"); num = input.nextInt(); }
    while (num == 0) {
    total = a + b + c + d + e;
    } System.out.println("The total salemoney of product is %f\n" + total);
    }
    }
      

  7.   

    while(num=0){ double total=a+b+c+d+e;
    }楼主首先这里面的=号,各位前辈已经说了,可是当你的执行到这的时候,你的abcde根本就没定义呀?肯定会出错呀?你定义的是在你的switch里面定义的,如果,num=0,就根本执行不到switch,就更不必说初始化赋值什么的了!
      

  8.   

    把abcde 定义到while 外面去吧  ,  ==号换下
      

  9.   

    double total = a + b + c + d + e;
    这个里面,你的变量abcde都超出了switch范围,当然找不到了
    而且while(num=0),这个是赋值语句,题目中你是要判断num是否为0,while(num==0),要这样判断