By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,553 Members | 894 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,553 IT Pros & Developers. It's quick & easy.

anyone can help me out to convert it to c++. i am a fresh student .

P: 1
Initialize total to zero

Initialize counter to zero

Input the first grade

while the user has not as yet entered the sentinel

add this grade into the running total

add one to the grade counter

input the next grade (possibly the sentinel)

endwhile



if the counter is not equal to zero

set the average to the total divided by the counter

print the average

else

print 'no grades were entered'

endif
3 Weeks Ago #1
Share this Question
Share on Google+
2 Replies

dev7060
Expert 100+
P: 336
  • initialize/set -> assignment operator
  • input -> input stream object
  • 'while the user' -> loop
  • add -> '+' operator
  • print -> output stream object
  • if -> if conditional
  • use += with 'total'
  • average (should be float/double) -> (sum of all values)/(total number of values)
It's mentioned where the loop or if block ends. Boolean conditions are stated as well.
3 Weeks Ago #2

P: 70
Hello,

you can refer following syntax for your program:

Initialize total and counter as follow

Expand|Select|Wrap|Line Numbers
  1. int total=0;
  2. int counter=0; 
  3. int grade=0;
  4. int average=0;
for input grade use cin

Expand|Select|Wrap|Line Numbers
  1. cin>>grade;
for loop use while loop
Expand|Select|Wrap|Line Numbers
  1. while (sentinel) {
  2.  cin>>grade;
  3.  total=total+grade;
  4.  counter=counter+1;
  5. }
  6. if(counter!=0)
  7. {
  8. average=total/counter;
  9. cout<<"Average"<<average;
  10. }
  11. else
  12. {
  13. cout<<"No grades were entered";
  14. }
  15.  
  16.  
2 Weeks Ago #3

Post your reply

Sign in to post your reply or Sign up for a free account.