Loop's
#1

Ok, I'm in a Computer Science/Programming class whatever you wanna call it in school and my teacher has asked me to do some weird shit.

Basically she's said(yes its a she omfg) i need to explain to her in English(so words) not in a code(Probably java or C++) how i can make a loop.
Heres the problem or whatever:
I need to explain to a coder to make a program for a user that asks to input 2 numbers to add up to less than 20 and if its less than 20 but greater than 0 display a dialog but if the user enters 2 numbers that add up greater than 20 make them do it again(loop).

i don't know if ive explained that right

if num1 + num2 are <20 but <0
show dialog
if num1 + num2 are >=20
loop

Need to explain it in english so if im a project leader and i have a team of programmers they will understand what i want.
I don't know why the fuck we're learning this i just wanna do some scripting, if anyone understands what i mean puhlease help.
Reply
#2

The program will allow the user to enter two numbers into the ***** (dialog, console, textbox?) ***** and then the program will add these numbers together to produce a value, if the value entered is less than twenty and greater than zero then the program will display a dialog to the user (stop execution here?) but if the value is greater than nineteen or less than one then the program will restart itself once again asking the user to enter two numbers for it to add together.

Something like that ?

The "( )" bits need filling in and removing etc but a few tweaks and that would be ok I think.
Reply
#3

That's exactly what i want but i need to explain how to make it restart/loop again.
Reply
#4

Quote:
Originally Posted by V1ceC1ty
That's exactly what i want but i need to explain how to make it restart/loop again.
We are going to be creating a program which works in a loop, what this means is that the program will repeat it's routine an infinite number of times until the programs process is closed by the user or system. The program will consist of a user input which will take two numbers from the user and add these numbers together to produce a value, if the value is less than twenty and greater than zero then the program will display a dialog to the user but if the value is greater than nineteen or less than one then the dialog will not be shown to the user. The program will now repeat this routine following the same pattern each time until it's closed, this is an unconditional loop and infinite as explained above.

Maybe something like that or do you mean you need to explain how a loop actually works as in conditionals and execution of the routines like a while(), program flow and all that?
Reply
#5

Quote:
Originally Posted by Donny
Maybe something like that or do you mean you need to explain how a loop actually works as in conditionals and execution of the routines like a while(), program flow and all that?
Yeah kinda like this
Quote:

if num1 + num2 are <20 but <0
show dialog
if num1 + num2 are >=20
loop

Reply
#6

K dis;

Okay guys, today we're going to write a program.
This program is going to accept 2 integer parameters, num1 and num2.

Upon running the program, the user will be prompted for two numbers.
The program will then add the two numbers together, if the sum is between 0 and 19, a dialog will be show - otherwise, the user shall receive an error message and be prompted for the two numbers again. For simplicity the prompt will be looped inside a while loop.

I write you java code, dunno if it helps or not :3
Код:
import java.util.Scanner;
public class SumAuth {

  public SumAuth() {
  }
  
  public static void main(String[] args)
  {
  	Scanner scan = new Scanner(System.in);
  	System.out.print("Enter the first number: ");
  	int num1 = scan.nextInt();
  	System.out.print("Enter the second number: ");
  	int num2 = scan.nextInt();
  	
  	int sum = num1+num2;
  	
  	while(sum >= 20 || sum < 0)
		{
			System.out.println("ERROR : Sum of the two numbers is not between 0 and 19");
			System.out.print("Enter the first number: ");
	  		num1 = scan.nextInt();
	  		System.out.print("Enter the second number: ");
	  		num2 = scan.nextInt();
			sum = num1+num2;
		}
		
	System.out.println("suces!");
  }  
  
}
Reply
#7

Quote:
Originally Posted by iLinx
I write you java code, dunno if it helps or not :3
Код:
stuffs
Thanks for your help, ill see what she says if i show her this. What i really needed is to explain how to loop briefly in English but oh well.
Reply
#8

Quote:
Originally Posted by V1ceC1ty
Quote:
Originally Posted by Donny
Maybe something like that or do you mean you need to explain how a loop actually works as in conditionals and execution of the routines like a while(), program flow and all that?
Yeah kinda like this
Quote:

if num1 + num2 are <20 but <0
show dialog
if num1 + num2 are >=20
loop

Go here >> Control flow & While, I'm sure you can get alot of info from those.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)