Write an interactive C++ program that prompts the user for ten (10) real numbers and calculate the sum, average, and prints the result. Hint: you may use an array to store the data.

Program requirements:
- The program must contain a class in which all the required private and public identifiers and the following functions must be defined.
- The program must contain three or more functions using parameters. These functions should read the data, calculate the sum, find the average, and print the results.

C++
#include "stdafx.h"
#include <iostream>
using namespace std;


// class with identifiers and functions
class real
{
private:
double n[10],s;                     // declarations
int i;
double avg;


public:
real()
{
s=0;
}


void read()


{
cout<<"Please Enter 10 Numbers"<<endl;
for (i=0;i<10;i++)
{


cout<<"You have Entered Number:";
cin>>n;
}
};


void print()
{


for (i=0;i<10;i++)
s=s+n;



avg=s/10;



cout<<"The Sum           ="<<s<<endl;
cout<<"The Average      ="<<avg<<endl;
}
};
int main()
{
real a;


a.read();


a.print();
system("PAUSE");
return 0;
}
#include "stdafx.h"
#include <iostream>
using namespace std;

// class with identifiers and functions
class real
	{
private:
	double n[10],s;						// declarations
	int i;
	double avg;
	
public:
	real()
	{
		s=0;
	}

	 void read()
	
	 {
		 cout<<"Please Enter 10 Numbers"<<endl;
		for (i=0;i<10;i++)
		{
			
			cout<<"You have Entered Number:";
		cin>>n[i];
		}
	 };

	void print()
	{
	
		for (i=0;i<10;i++)
		s=s+n[i];

	
		avg=s/10;
	
	
		cout<<"The Sum           ="<<s<<endl;
		cout<<"The Average	  ="<<avg<<endl;
	}
};
	int main()
{
    real a;

    a.read();
    
	a.print();
system("PAUSE");
    return 0;
}

ur code looks pretty alright this time..... it shud work.... or r u still having any problem?.... n wat kinda problem?.... one more thing to ask u.... did u put the class function in the stdafx.h file?.... or y did u include this file?.... take it easy! :)

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.