not able to find the average in serial please help

int b[ 7 ];
int number;
int select;
int largest;
float avg;
int sum=0;
int que;// for waiting the loop
#define WAIT 2000000
unsigned long counter;
int nil=0;
float degC;
static FILE uart00 = {0};
void setup(void) {
//int b[ 7 ];
int i;
//int number = 0;
DDRB |= B10000000 ;// make pin 13(port B) as output
UCSR0A = B00000000; //single transmission speed, multiprocessor disabled
UCSR0B = B00011000; //enable Rx & Tx
UCSR0C = B00000110; //asynchronous, no parity, 1 stop, 8 bits
UBRR0 = 103; //load the value for 9600 bps baud rate into whole UBRR register
que=0;
fdev_setup_stream (&uart00, TX, RX, _FDEV_SETUP_RW);
stdin= stdout = &uart00 ; //the uart is defined as the standard inputa/output device STDOUT.
}
static int RX(FILE *stream) {
//do nothing until data is received and is ready to be read from UDR0; wait for USART RX Complete flag
while ((UCSR0A & (1 << RXC0)) == 0) {};
//when flag is set read data from USART UDR0 register and return it
return(UDR0);
}
static int TX(char TXData , FILE *stream) {
//do nothing until UDR0 is ready for more data to be written to it; wait for USART UDRE flag
while ((UCSR0A & (1 << UDRE0)) == 0) {};
//when flag is set send data by placing the byte into UDR0
UDR0 = TXData;
return 0 ;
}
void loop(void) {

if( que == 0)
{
PORTB= PORTB | B10000000; // Turn ON LED pin13
printf("-------------------------------\n\r"); //display messages
printf(“Nandu Raj\n\r”); //display messages
printf(“Students ID : 11111111111\n\r”);
printf("-------------------------------\n\r"); //display messages
for( counter = 0; counter< WAIT; counter++) {}//wait for 2 sec
PORTB =PORTB & B01111111;
que=1;
}
printf(“Select option 1 or 2\n\r”); //display messages
printf(“1)Weekly Data\n\r”);
printf(“2)Show Report\n\r”);
scanf("%d",&select);
printf("%d\n\r",select);

if(select ==1)
{
//printf(“select 1\n\r”);
int i;
for( i = 0 ; i < 7; i++ )
{
if(i==0){printf(“monday: “);scanf( “%d”, &number );printf(”%d\n\r”,number);b[ i ] = number; }
if(i==1){printf(“tue: “);scanf( “%d”, &number );printf(”%d\n\r”,number);b[ i ] = number; }
if(i==2){printf(“wed: “);scanf( “%d”, &number );printf(”%d\n\r”,number);b[ i ] = number; }
if(i==3){printf(“thur: “);scanf( “%d”, &number );printf(”%d\n\r”,number);b[ i ] = number; }
if(i==4){printf(“fri: “);scanf( “%d”, &number );printf(”%d\n\r”,number);b[ i ] = number; }
if(i==5){printf(“sat: “);scanf( “%d”, &number );printf(”%d\n\r”,number);b[ i ] = number; }
if(i==6){printf(“sun: “);scanf( “%d”, &number );printf(”%d\n\r”,number);b[ i ] = number; }
}
}
else if(select==2)
{
largest = b[0];
int i;
for (i = 0; i < 7; i++)
{
sum=b + sum; *
_ if (b > largest) {_
_ largest = b;
}
}
printf("%d\n\r",largest);
printf("%d\n\r",sum);
//average*
// for (i = 0; i < 7; i++)
// {
// sum=b + sum;
// }
avg= (float)sum/7.0;

* printf("%0.2f\n\r",avg);
}
else*

* {}*_

}

Which Arduino are you using for this sketch?

And read How to post code properly and fix up your code with code tags.

Pete

Are you building this project under arduino because I could never get arduino to accept fdev_setup_stream (&uart00, TX, RX, _FDEV_SETUP_RW); I would always get an error.

Note that printf() do not accept floats, you will find a fix in the code below to print the average.

BTW, on an UNO, PIN 13 is on PORTB5, not PORTB7 (but maybe you are using a bare bone 328P on an specific PCB ??).

int b[ 7 ];
int number;
int select;
int largest;

float avg = 1.00000;  // Depending on the needed precision

int sum;
int que;// for waiting the loop
#define WAIT (2000000)
uint32_t counter;
int nil;
float degC;
static FILE uart00 = {0};


void setup(void) {

  DDRB |= 1 << DDB5; // make pin 13 (port B) as output
  UCSR0A = 0;//B00000000; //single transmission speed, multiprocessor disabled
  //UCSR0B = B00011000; //enable Rx & Tx
  UCSR0B = 1 << RXEN0 | 1 << TXEN0; //enable Rx & Tx
  //UCSR0C = B00000110; //asynchronous, no parity, 1 stop, 8 bits
  UCSR0C = 1 << UCSZ00 | 1 << UCSZ01; //asynchronous, no parity, 1 stop, 8 bits
  UBRR0 = 103;        //load the value for 9600 bps baud rate into whole UBRR register
  //que = 0;
  fdev_setup_stream (&uart00, TX, RX, _FDEV_SETUP_RW);
  stdin = stdout = &uart00 ; //the uart is defined as the standard inputa/output device STDOUT.
}



void loop(void) {

  if ( que == 0)
  {
    // PORTB= PORTB | B10000000; // Turn ON LED pin13
    PORTB |= 1 << PORTB5;// Turn ON LED pin13
    for ( counter = 0; counter < WAIT; counter++) {} //wait for 1 sec
    PORTB ^= 1 << PORTB5; //Turn OFF LED pin13
    for ( counter = 0; counter < WAIT; counter++) {} //wait for 1 sec
    PORTB ^= 1 << PORTB5; //Turn ON LED pin13
    for ( counter = 0; counter < WAIT; counter++) {} //wait for 1 sec
    PORTB ^= 1 << PORTB5; //Turn OFF LED pin13

    printf("-------------------------------\n\r"); //display messages
    printf("Nandu Raj\n\r"); //display messages
    printf("Students ID : 11111111111\n\r");
    printf("-------------------------------\n\r"); //display messages
    que = 1;
  }
  printf("Select option 1 or 2\n\r"); //display messages
  printf("1)Weekly Data\n\r");
  printf("2)Show Report\n\r");
  scanf("%d", &select);
  printf("Your selection ---> %d\n\r", select);


  if (select == 1)
  {
    //printf("select 1\n\r");

    for ( int i = 0 ; i < 7; i++ )
    {
      if (i == 0) {
        printf("monday: ");
        scanf( "%d", &number );
        printf("%d\n\r", number);
        b[ i ] = number;
      }

      if (i == 1) {
        printf("tue: ");
        scanf( "%d", &number );
        printf("%d\n\r", number);
        b[ i ] = number;
      }
      if (i == 2) {
        printf("wed: ");
        scanf( "%d", &number );
        printf("%d\n\r", number);
        b[ i ] = number;
      }
      if (i == 3) {
        printf("thur: ");
        scanf( "%d", &number );
        printf("%d\n\r", number);
        b[ i ] = number;
      }
      if (i == 4) {
        printf("fri: ");
        scanf( "%d", &number );
        printf("%d\n\r", number);
        b[ i ] = number;
      }
      if (i == 5) {
        printf("sat: ");
        scanf( "%d", &number );
        printf("%d\n\r", number);
        b[ i ] = number;
      }
      if (i == 6) {
        printf("sun: ");
        scanf( "%d", &number );
        printf("%d\n\r", number);
        b[ i ] = number;
      }
    }
  }
  else if (select == 2)
  {
    largest = b[0];

    for (int i = 0; i < 7; i++)
    {
      sum = b[i] + sum;
      if (b[i] > largest) {
        largest = b[i];
      }
    }
    printf("Largest = %d\n\r", largest);
    printf("Sum = %d\n\r", sum);
    printf("Average = ");
    
    avg = (float)(sum / 7.00000);
   
    //printf("%0.2f\n\r", avg);  // Printf do not accept floats !!
   
    PrintFloat(avg);
  }
  // else
  // {}

}

static int RX(FILE *stream) {
  //do nothing until data is received and is ready to be read from UDR0; wait for USART RX Complete flag
  while ((UCSR0A & (1 << RXC0)) == 0) {};
  //when flag is set read data from USART UDR0 register and return it
  return (UDR0);
}

static int TX(char TXData , FILE *stream) {
  //do nothing until UDR0 is ready for more data to be written to it; wait for USART UDRE flag
  while ((UCSR0A & (1 << UDRE0)) == 0) {};
  //when flag is set send data by placing the byte into UDR0
  UDR0 = TXData;
  return 0 ;
}

void PrintFloat(float v)
{
  
  float dec = (v - (int)v) * 100000; // depending on the number of digits in the decimal..
  printf("%d.%05d", (int)v, (int)dec);
  printf("\n\r");
}