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 to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b.

WAP TO ACCEPT THE BASIC SALARY OF EMPLOYEES & CALCULATE NET SALARY   #include stdio.h> #include conio.h>   void main() {                    float Basi

Addition of array elements: #define rows 3 #define cols 3 void main() {                 int i=0,j=0,sum=0;                 int arr[rows][cols];

A: In C++, the definition of NULL is 0, thus there is only an aesthetic difference. I prefer to ignore macros, so I employ 0. Another difficulty with NULL is that people sometimes


A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome

Area under the curve Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve bet

Use of random function: int main(void) {    int i,j;         for(j=0;j       {      // randomize();       for(i=0;i                  printf("%d\n", ran

write a C rpogram that can display the transpose form of a ciphertext matrix.Prompt users to provide row and coloumn number of matrix.Then user will input plaintext and the program

sample of program that use in bubble sort using assignment operator in c++