
-----------------------------------
munt4life
Tue Oct 12, 2010 7:59 pm

Turing loop help
-----------------------------------
Hey could someone help me on these, i found them on a small quiz and found them tough. Thanks!


1.	Create a program that gets ten numbers from the user and computes the average of the numbers.							

2.	Create a program that allows the user to try to guess a number from 1 to 1000.  The number to be guessed will be randomly generated by your program.  After each guess tell the user if the real number is higher of lower.  If they guess the right number in 10 or fewer guesses tell them they did a good job, otherwise don't be as nice.

-----------------------------------
Sur_real
Tue Oct 12, 2010 9:46 pm

Re: Turing loop help
-----------------------------------
TURING!!!!!! It's been a while.
Since I don't want to provide any direct answers...

For 1. It's actually quite simple.

[code]
int count = 1;
int num = 0;
loop
{
  output "enter a number";
  get num;
  temp = num;
  num = num + temp; // Assuming you guys didn't do arrays yet but seriously arrays FTW
  count++; // increment counter
} exit when count==10; // So when the program ran 10 times you exit
avg = num/10;
output "the average is" + avg;
[/code]

For 2. A little more tricky.

[code]
int rand = createRandInt(1,1000); // Dunno the actually function but I'm sure you should've memorized it 
int count = 1;
int num = 0;
loop
{
  output "enter a number";
  get num;
  if numrand
    output num + " is greater than the random value";
  if num==rand;
    exit;
  count++;
}
if count 