Write a C program using do while to find and print the average of three exam results of a student that will entered as an input from the keyboard. It repeats as many times as the user wishes. The program will ask for entering new entry (student grades) confirmation and if the user enters ‘N’ or ‘n’ as an input the program will stop entering new student results and will be terminated.

I managed to do it until here

#include <stdio.h>
#include <conio.h>
void main ()
{
 int sum=0;
 int r1,r2,r3;
 float avg;
 char ch;

   printf("Enter the Marks of 1st Exam :	");
   scanf("%d",&r1);
   printf("Enter the Marks of 2nd Exam :	");
   scanf("%d",&r2);
   printf("Enter the Marks of 3rd Exam :	");
   scanf("%d",&r3);

  do
  {
   sum=r1+r2+r3;
   avg=sum*1.0/3;
   printf("The Avg is : %.2f",avg);
   printf("\nEnter the Marks of 1st Exam :	");
   scanf("%d",&r1);
   printf("Enter the Marks of 2nd Exam :	");
   scanf("%d",&r2);
   printf("Enter the Marks of 3rd Exam :	");
   scanf("%d",&r3);
  }
  while(ch=='n'||ch=='N');
  printf("The Avg is : %.2f",avg);


getche();
}

thanks

Recommended Answers

All 5 Replies

I managed to do it until here

So take the next step and do beyond here. Or do you actually have a specific question that we can answer?

So take the next step and do beyond here. Or do you actually have a specific question that we can answer?

let me tell you the particular area, in which i am facing problem.

1- It is not repeating, as the question says that . "It repeats as many times as the user wishes " It repeats only twice.

2- I can't manage to do as the question demands "if the user enters ‘N’ or ‘n’ as an input the program will stop entering new student results and will be terminated" The N and n thing ?

do{
//...
} while(ch=='n'||ch=='N');

(1) where is 'ch' assigned?

(2) your code, as it is, will continue to "do" when the 'ch' is either 'n' or 'N'.... isnt this backwards? shouldn't it be while(ch != 'n' && ch != 'N') ?

.

do{
//...
} while(ch=='n'||ch=='N');

(1) where is 'ch' assigned?

(2) your code, as it is, will continue to "do" when the 'ch' is either 'n' or 'N'.... isnt this backwards? shouldn't it be while(ch != 'n' && ch != 'N') ?

.

while(ch != 'n' && ch != 'N') this code did helped me, as the programs ask me as many time as i wish, but as i enter n or N, i don't know what happens to the program, it doesn't really make send whats it doing.

i cannot assign a value to ch as the questions demands that it should be ENTERED.

Thanks for the Reply : )

wellllllll............. perhaps you could use scanf() to assign it to 'ch' based on the response of the user to a question?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.