anonymous
  • anonymous
Please explain this C code (follows in text). It is code for a guessing game (guess the right number). I am a beginning student and this example comes from my textbook, but I can understand the while loop, if, else, the call to functions; also it uses words as variables and I can't help interpreting the meaning, where as a computer just sees it as a variable or string.
MIT 6.00 Intro Computer Science (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
schrodinger
  • schrodinger
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
#include #define TARGET 17 #define LOW 0 #define HIGH 100 #define TRUE 1 #define FALSE 0 int process( int guess, int target ); int. main (void) { Int a_guess, correct; correct = FALSE; printf( “I’m thinking of a number between %d and %d.\n”, LOW, HIGH ); while ( correct == FALSE ) { printf( “Try to guess it now. “ ); scanf( “%d”, &a_guess ); correct = process( a_guess, TARGET ); } return 0; int process( int guess, int target ) { If ( guess < target ) printf( “Too low!\n” ) else if ( guess > target ) printf( “Too high!\n” ); else { printf( “You guessed it!\n” )’ return TRUE; } Return FALSE; }
KonradZuse
  • KonradZuse
Whuat exactly is the issue?
anonymous
  • anonymous
I don't understand the nuts and the bolts. Like how the while function works, how correct is assigned FALSE, then correct is assigned process. In class, we are just breezing through everything, and I seem stuck because I can't comprehend it.

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
I'm kind of piecing it together, the more I look at it, the 'process' function eventually returns FALSE, which tells the while loop to terminate.
KonradZuse
  • KonradZuse
Basically while works that it will keep asking the question until your "target" guess is correct. Low is 0, high is 100. The target is 17. So basically you are asked a # between 0 and 100. While it's false, it will ask you to enter a number, if you enter ANY number besides 17 you will goto the if statements stating it if is too high, or too low. When you enter 17 it will tell you you are correct, and will set it to true, so the while loop stops.
anonymous
  • anonymous
Thank you, my text book is kind of verbose and detailed and speaks the 'C language'. It never gives a 'English' explanation as you gave above. So I'm having trouble with basics here and there, but I'm getting it.
KonradZuse
  • KonradZuse
yup anything else needed?
anonymous
  • anonymous
OK, here is another code, my classmate started, it is not finished, you might get the idea; the assignment was to write a menu-driven mini statistics package. I guess I get a little intimidated by all the code, but I don't follow a lot of this, if you can tell me what is going on.
anonymous
  • anonymous
#include #include "stdafx.h" #include #define MAX 200 void print_inventory( int inventory[], int numbitems); int stdDev( int inventory[], int num_items, int meen) int input_inventory( int inventory[], int maximum); int largest( int inventory[], int n); int mean(int inventory[],int n); /******************************************main***************************/ int main( void ) { int inventory[MAX]; int num_item; int large; int meen; int dev; printf( "enter 1 - 200 differnt numbers\n"); num_item = input_inventory( inventory, MAX); print_inventory( inventory, num_item ); large = largest( inventory, num_item); printf( "%d is the largest number\n",inventory[large]); meen = mean( inventory, num_item ); printf(" mean of array is %d\n", meen); dev = stdDev( inventory, num_item, meen); printf(" the standard deviation is %d",dev); return 0; } /***************************input items***************************/ int input_inventory( int inventory[], int maximum) { int index = 0; scanf_s( "%d", &inventory[ index] ); while ( index < maximum && inventory[ index ] != -1) { index++; scanf_s( "%d", &inventory[index] ); } if (index == -1) { printf( "No room for more items."); return( index+1); } else return ( index); } /*************************print items******************/ void print_inventory( int inventory[], int numitems) { int index; for( index= 0; index < numitems; index++) { printf(" item number %d;\t", index +1); printf( "number on hand %5d\n",inventory[index]); } } /****************************mean*******************/ int mean(int inventory[],int n) { int i; int sum=0; for(i=0;i
KonradZuse
  • KonradZuse
he's creating a bunch of methods, and each method does something different. In coding making certain bits of code is important. Lets say you wan tto add something, so you could make a method like int add(int a, int b) { return a + b; }
anonymous
  • anonymous
OK, thank you. I think I'm going to stop looking at the vast code and being intimidated, I eat it in little nugget size like your example.
anonymous
  • anonymous
http://myopencourses.com/subject/coding-theory - see if this helps

Looking for something else?

Not the answer you are looking for? Search for more explanations.