Bamaboy53
Oct 29, 2009, 12:32 PM
Below you can see that I have a C++ program that should calculate and display the average value to the user, but after entering numbers for calculation the output will not display average. Help!
#include<iostream>
using namespace std;
class average
{
private:
int arr[100]; // Variable to hold the numbers entered by the user
int total; //To hold the total value of the numbers entered
float avg; //To hold the average value of the entered numbers
int count; //To hold the total number of elements to be entered by the user
//Constructor
public:
average()
{
cout<<"How Many Numbers do you want to Enter?"<<endl<<"NUMBER : ";
cin>>count;
total = 0;
}
//Member Functions
void get_input()
{
cout<<endl<<"Please Enter The Numbers : "<<endl;
for(int I=0;i<count;i++)
{
cout<<"Number "<<(I+1)<<" : ";
cin>>arr[i];
}
}
void calculate_avg()
{
for(int I=0;i<count;i++)
{
total += arr[i];
}
avg = (float)total/count;
}
void display()
{
cout<<endl<<"Average of Entered Numbers are : "<<avg<<endl;
}
};
//Main Function
int main()
{
average avrg;
avrg.get_input();
avrg.calculate_avg();
avrg.display();
return 0;
}
#include<iostream>
using namespace std;
class average
{
private:
int arr[100]; // Variable to hold the numbers entered by the user
int total; //To hold the total value of the numbers entered
float avg; //To hold the average value of the entered numbers
int count; //To hold the total number of elements to be entered by the user
//Constructor
public:
average()
{
cout<<"How Many Numbers do you want to Enter?"<<endl<<"NUMBER : ";
cin>>count;
total = 0;
}
//Member Functions
void get_input()
{
cout<<endl<<"Please Enter The Numbers : "<<endl;
for(int I=0;i<count;i++)
{
cout<<"Number "<<(I+1)<<" : ";
cin>>arr[i];
}
}
void calculate_avg()
{
for(int I=0;i<count;i++)
{
total += arr[i];
}
avg = (float)total/count;
}
void display()
{
cout<<endl<<"Average of Entered Numbers are : "<<avg<<endl;
}
};
//Main Function
int main()
{
average avrg;
avrg.get_input();
avrg.calculate_avg();
avrg.display();
return 0;
}