If a number of test cases isn't provided, when should my program stop reading input?

When should my program stop reading input for problems without multiple test cases?

Some problems do not have multiple test cases, and are instead judged by testing your code multiple times on different input files. If the problem statement does not say there are multiple cases, do not assume there are.

Other problems mention multiple test cases, but don’t provide any limits on how many there could be. Your program should stop at the end of the input file. All programming languages have a way of testing this; for example, in Java, a BufferedReader’s readLine() method will return null. In C++, scanf returns the number of items successfully matched; EOF if it reaches the end of the file.

Read your programming language’s documentation to find out what it returns.

If you choose to test your program without the redirection method mentioned earlier, you can generate an EOF (end-of-file) character by pressing Ctrl-Z.

2 Likes

import java.text.DecimalFormat;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("#.00");
final double ch=0.50f ;
int WdAmnt =input.nextInt();
Double PrevBalnc=input.nextDouble();
boolean flag = false;
if(WdAmnt%5 ==0 && WdAmnt<=2000. && PrevBalnc <=2000.00 && WdAmnt>0 && PrevBalnc>=0.00)
flag=true;
else
flag=false;
if(WdAmnt!=0 && WdAmnt<=PrevBalnc && flag)
{
PrevBalnc=PrevBalnc-(WdAmnt+ch);
}
System.out.println( df.format(PrevBalnc));
}
}

whats wrong withis code?

Edit it and post it as a code. I don’t think anyone can understand this as it is. ( Take EDIT, Select your code, and press Ctrl + k if you’re on Windows, or look at the options on the EDIT and you will see code sample )

1 Like

In C++,
while(cin>>n)

To terminate the input, you can use Ctrl+Z

1 Like

used in C/C++


 while(scanf("%d",&n)!=EOF){
   //your code is here
  }

HAPPY CODING

1 Like