Hello everyone, so for this program i have to read names and numbers from the file, from there I have to use the numbers to calculate the area of the circle, but I cant really figure out how to fix my function that calculates the area, as of now it prints out the same number for all people(which im not sure how my program keeps getting that number) so any ideas on how to fix it? ps. Im required to use a string array and double array
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
usingnamespace std;
double CalcCircleArea(double [], int SIZE);
constint SIZE=12;
constdouble PI = 3.14;
int main() {
string FirstName[SIZE],dummy[SIZE];
double circleArea[SIZE],areaTotal=0;
ifstream infile("PiiCircles.txt"); //opens file
if (!infile) // checks if file opened
{
cout << "Could not open input file\n"; // tells user if file didnt open correctly
return 1;
}
else
{
for(int i=0; i < SIZE;i++)
{
infile >> FirstName[i] >> dummy[i] >> circleArea[i];
}
areaTotal =CalcCircleArea(circleArea,SIZE);
for(int i=0; i <SIZE; i++)
{
cout << left << setw(10) << FirstName[i] << areaTotal <<" " <<endl;
}
}
infile.close();
return 0;
}
double CalcCircleArea(double circleArea[SIZE], int SIZE)
{
double area=0;
for(int i=0; i <SIZE; i++)
{
area= PI * circleArea[i] * circleArea[i] ;
}
return area;
}
current output:
LoriBeth 138474
Chachi 138474
Richie 138474
Howard 138474
Marion 138474
Joanie 138474
Al 138474
Arthur 138474
Ralph 138474
Roger 138474
Jenny 138474
Potsie 138474
file used:
LoriBeth Allen 79
Chachi Arcola 125
Richie Cunningham 171
Howard Cunningham 255
Marion Cunningham 252
Joanie Cunningham 234
Al Delvecchio 122
Arthur Fonzarelli 255
Ralph Malph 165
Roger Phillips 61
Jenny Piccalo 55
Potsie Weber 210
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
usingnamespace std;
double CalcCircleArea(double);
constint SIZE=12;
constdouble PI = 3.14;
int main() {
string FirstName[SIZE],dummy[SIZE];
double circleArea[SIZE],areaTotal=0;
ifstream infile("circle_area_size.txt"); //opens file (use your file name)
if (!infile) // checks if file opened
{
cout << "Could not open input file\n";
return 1;
}
else
{
for(int i=0; i < SIZE;i++)
{
infile >> FirstName[i] >> dummy[i] >> circleArea[i];
areaTotal = CalcCircleArea(circleArea[i]);
cout << left << setw(10) << FirstName[i] << areaTotal <<" " <<endl;
}
}
infile.close();
return 0;
}
double CalcCircleArea(double diameter)
{
double area=0;
area= PI * diameter * diameter/4 ;
return area;
}
LoriBeth 4899.19
Chachi 12265.6
Richie 22954.2
Howard 51044.6
Marion 49850.6
Joanie 42983.5
Al 11683.9
Arthur 51044.6
Ralph 21371.6
Roger 2920.99
Jenny 2374.63
Potsie 34618.5
Program ended with exit code: 0