Welcome

Hi! This blog is for beginners of c++ and java .You can check and pick codes for your programming assignments. This will also help you to understand the concepts of these programming languages. Its all about programming.

Loops Practise(Average)

Wednesday, May 18, 2011

#include <iostream.h>
int main ()
{
    long int v=0;  //v for value
    float c=0;
    long int s=0;  //s for sum
    float avg;  //avg for average
    cout <<"Enter value \n";
    cin >> v;
    while (v!=0) //loop until "v"=o
    {
        c=c++;
        s=s+v;
        cout <<"\n\nEnter another value (0 to get average)) = ";
        cin >> v;
    }
    avg=s/c;
    cout <<"\naverage is = " << avg;
    return 0;

}