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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hadekhan
    New Member
    • Nov 2020
    • 1

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

    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
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 656

    #2
    • 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.

    Comment

    • AjayGohil
      New Member
      • Apr 2019
      • 83

      #3
      Hello,

      you can refer following syntax for your program:

      Initialize total and counter as follow

      Code:
      int total=0;
      int counter=0; 
      int grade=0;
      int average=0;
      for input grade use cin

      Code:
      cin>>grade;
      for loop use while loop
      Code:
      while (sentinel) {
       cin>>grade;
       total=total+grade;
       counter=counter+1;
      }
      if(counter!=0)
      {
      average=total/counter;
      cout<<"Average"<<average;
      }
      else
      {
      cout<<"No grades were entered";
      }

      Comment

      Working...