Design a game in c, C/C++ Programming

Design a game in c:

const DODGERS = 0;

const GIANTS = 1;

 

void main(void)

{

   int scoreboard [2][9];    // An array two rows by nine columns

   int team, inning;

   int score, total;

 

   randomize();              // Initialize random number generator

 

   // Generate the scores

   for (team = DODGERS; team <= GIANTS; team++) {

      for (inning = 0; inning < 9; inning++) {

         score = random(3);

         if (score == 2)             // 1/3 chance to score at least a run

            score = random(3) + 1;   // 1 to 3 runs

         if (score == 3)

            score = random(7) + 1;   // Simulates chance of a big

                                     // inning of 1 to 7 runs

         scoreboard[team][inning] = score;

      }

   }

 

   // Print the scores

   cout << "\nInning\t1   2   3   4   5   6   7   8   9  Total\n";

   cout << "Dodgers\t";

   total = 0;

   for (inning = 0; inning <= 8; inning++) {

      score = scoreboard[DODGERS][inning];

      total += score;

      cout << score << "   ";

   }

   cout << total << "\n";

 

   cout << "Giants\t";

   total = 0;

   for (inning = 0; inning < 9; inning++) {

      score = scoreboard[GIANTS][inning];

      total += score;

      cout << score << "   ";

   }

   cout << total << "\n" ;

}

 

 

Posted Date: 10/18/2012 7:52:24 AM | Location : United States







Related Discussions:- Design a game in c, Assignment Help, Ask Question on Design a game in c, Get Answer, Expert's Help, Design a game in c Discussions

Write discussion on Design a game in c
Your posts are moderated
Related Questions
Write a program that reads data into an array of type int. You must use an array. The numbers input are attendance numbers at a conference. Keep a running average, number of events

A: auto: the default. Variables are created and initialized automatically while they are defined and destroyed at the ending of the block containing their definition. They are not

C Program for REVERSE THE STRING #include stdio.h> #include conio.h> #include string.h> void main() {           char name[30];           char *s;

Aim: To implement a program to swap two numbers using reference arguments. Code: void swap(int *a, int *b) {             int temp;             temp=*a;

Sorted directory - C++ program: Write a program in c to sorting a directory. int main( int argc, char *argv[] ) {     if( argc 3 )         {         cerr

Problem: (a) Show the Java approach to event processing by explaining how event handling works in Java. Make use of a suitable example to support your answer. (b) Describe


Develop Online Slot Video Game for Facebook Prepare an online slot video game for a Facebook promotion in order to draw new visits and Increase the number of "likes" of the Face

dispaly the last ant on rod

Compound Assignment Operators Apart from the binary and the unary arithmetic operators, we also have compound assignment operators. These are +=, -=, *=, /=, %=. Using these op