-3
package homeWork;

import java.util.*;

public class MainClass {

public static void main(String[] args){
    Scanner conIn = new Scanner(System.in);
    ShoppingBag sb = new ShoppingBag(0.06f);
    int count = 0;
    float cost = 0.0f;
    System.out.print("Enter count (0 to stop):");
    count = conIn.nextInt();

    while(count){
        System.out.print("Enter cost: ");
        cost = conIn.nextFloat();
        sb.place(count, cost);
        System.out.print("Enter count (0 to stop):");
        count = conIn.nextInt();
    }

}

}

I get an error for the while loop and cannot run the program. When I tried converting count to boolean everything got wonky. Not sure what my best course of action should be.

Balwinder Singh
  • 2,272
  • 5
  • 23
  • 34
C.Metzan
  • 29
  • 1
  • 3

2 Answers2

4

Different from other programming languages (such as C), java only accepts boolean expressions at loop control. Then you should do something like as:

//prev code
while(count != 0){
    //your loop
}
pedrohreis
  • 1,030
  • 2
  • 14
  • 33
0

syntax for while:

while(condition)
{
    //statements
}

for your question have a increment variable i

while(count<i)
{
    //code
    i++;
}