How do i find the avg and sum yung any kind of loop? answer pls this is my code so far
#include <iostream>
using namespace std;
int main()
{
int num,avg;
float input, sum=0, AVG;
cout<<"Input a number"<<endl;
cout<<"Input No 1"<<endl;
cin >> num;
cout<<"Input No 2"<<endl;
cin >> num;
cout<<"Input No 3"<<endl;
cin >> num;
for(int i = 1; i <= 2; i++){
cin >> input;
sum += input;
}
avg = sum / num;
cout << "average = " << avg << sum << endl;
#include <iostream>
usingnamespace std;
int main()
{
int num = 0;
float input = 0, sum = 0;
while (input != -1)
{
cout<<"Input a number (-1 to quit) : " ;
cin >> input;
if( input !=-1 )
{
num++;
sum += input;
cout << " Current total: " << sum << endl;
cout << " Current average: " << sum/num << endl;
}
}
return 0;
}
Input a number (-1 to quit) : 5
Current total: 5
Current average: 5
Input a number (-1 to quit) : 6
Current total: 11
Current average: 5.5
Input a number (-1 to quit) : -1
Exit code: 0 (normal program termination)