Solved

A dice that simutales 10 dice ..save them in an array element and sums the total nr of all of them?

Posted on 2003-10-24
7
353 Views
Last Modified: 2010-04-15
help me finish my program...A dice that simutales 10 dice ..save them in an array element and sums the total nr of all of them?

i have done this soo far!!

#include <stdio.h>
#include <stdlib.h>
#include<time.h>

int get_max(int a[], int x);
int summera(void);

int main(void)
{
      int i;
      int arr1;
      int nr;
      
      for (i = 0; i > 10; i++){
      tal = rand()%6 + 1;
      
      printf("dice nr %d\n",nr);
      
      
      

 return (0);
}

int get_max(int a[], int x)
{

        int i,
        cur_large;

        cur_large = a[0];



   for (i = 1; i < x; i++)
        {
                if (a [i] > cur_large)
                {
                        cur_large = a[i];
                }

        }
        return cur_large;



int summera(int arr[],int size)
{
      int summa;


   for (i = 0; i < size; i++)
   {
      summa = summa + arr[i];
   }

   printf ("Summan : %d\n", summa);
0
Comment
Question by:bosselini
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9613126
you are not calling any functions though you have defined
getmax and summera
perhaps this is what you want

#include <stdio.h>
#include <stdlib.h>
#include<time.h>

int get_max(int a[], int x);
int summera(void);

int main(void)
{
    int i;
    int arr1;
    int nr;
   
     for (i = 0; i > 10; i++){
    tal = rand()%6 + 1;
   
     printf("dice nr %d\n",nr);
    }  ======== close the for loop
     
    printf ("max value is %d\n", get_max (arr1, 10) );
    printf ("total sum is %d\n", summera (arr1, 10) );

 return (0);
}

int get_max(int a[], int x)
{

       int i,
       cur_large;

       cur_large = a[0];



  for (i = 1; i < x; i++)
       {
               if (a [i] > cur_large)
               {
                       cur_large = a[i];
               }

       }
       return cur_large;
} =========== this brace was missing


int summera(int arr[],int size)
{
    int summa=0; ===== initialize to 0


  for (i = 0; i < size; i++)
  {
     summa = summa + arr[i];
  }

  printf ("Summan : %d\n", summa);
} ============== missing brace
0
 
LVL 4

Expert Comment

by:n_fortynine
ID: 9615080
>>   for (i = 0; i > 10; i++){

You meant i < 10 :D
0
 
LVL 1

Expert Comment

by:osp70
ID: 9616007
If you can get the above code to compile let me know.  


#include <stdio.h>
#include <stdlib.h>
#include<time.h>

int get_max(int a[], int x);
int summera(void);

int main(void)
{
    int i;
    int arr1; ----> is this supposed to be an array?, chg to     kMaxDie = 10; int arr1[kiMaxDie];
    int nr;
   
     for (i = 0; i > 10; i++){
    tal = rand()%6 + 1;               -----> maybe it's been a long time since I've used C but where is tal declared?
                                                         is it supposed to be arr[i] = rand()%6 + 1;
   
     printf("dice nr %d\n",nr);
    }  ======== close the for loop
     
    printf ("max value is %d\n", get_max (arr1, 10) );
    printf ("total sum is %d\n", summera (arr1, 10) );

 return (0);
}

int get_max(int a[], int x)
{

       int i,
       cur_large;           ----------> this is okay but hard to read   would prefer ->  int i;
                                                                                                                     int cur_large;
       cur_large = a[0];



  for (i = 1; i < x; i++)
       {
               if (a [i] > cur_large)
               {
                       cur_large = a[i];
               }

       }
       return cur_large;
} =========== this brace was missing


int summera(int arr[],int size)
{
    int summa=0; ===== initialize to 0


  for (i = 0; i < size; i++)
  {
     summa = summa + arr[i];
  }

  printf ("Summan : %d\n", summa);  -------------> don't force user of routine to print things, take this out.  If you use
                                                                          this you will end up with the following output with above call
                                                                          > total sum is Summan : 30
                                                       -------------> need to add -> return summa;
} ============== missing brace

osp70
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:guitardude101
ID: 9619465
Hello,
  This is the approach I would use.
Here is a short program that does exactly what you asked.

#include <stdio.h>
#include <stdlib.h>

#define kNumDice 10
#define kMaxDie      6

void rollDice(int dice[], int numdice);
int totalDice(int dice[], int numdice);
void printDice(int dice[], int numdice);


int main(void)
{
      int dice[kNumDice], total;

      rollDice(dice, kNumDice);
      total = totalDice(dice, kNumDice);
      printDice(dice, kNumDice);
      
      printf("\ntotal = %d\n", total);

      return 0;
}

void rollDice(int dice[], int numdice)
{
      int index;

      for (index = 0; index < numdice; index++)
      {
            dice[index] = (rand() % kMaxDie) + 1;
      }
}

Sample Output:
Die 1 = 3
Die 2 = 5
Die 3 = 4
Die 4 = 2
Die 5 = 2
Die 6 = 6
Die 7 = 1
Die 8 = 4
Die 9 = 1
Die 10 = 1

total = 29
0
 
LVL 1

Expert Comment

by:guitardude101
ID: 9619475
I missed this when I copied and pasted


int totalDice(int dice[], int numdice)
{
      int sum = 0, index;
      
      for (index = 0; index < numdice; index++)
      {
            sum += dice[index];
      }
      return sum;
}


void printDice(int dice[], int numdice)
{
      int index;

      for (index = 0; index < numdice; index++)
      {
            printf("Die %d = %d\n", index + 1, dice[index]);
      }
}


0
 
LVL 1

Accepted Solution

by:
guitardude101 earned 50 total points
ID: 9823675
My answer is correct. I provided a full program with the output..... and I would like some points.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question