This program asks you to input three friends and the diameter of their pizza slice.
It then computes the area of the pizza and sees who has the largest slice.
I need some help trying to put getline into my string function to get rid of the repetition in the code.
#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
using namespace std;
string presentStringPrompt(string);
double presentDoublePrompt(string);
double computeAreaOfCircle(double);
const double pi = 3.14159;
int main() {
string first;
string second;
string third;
double diameter;
double radius;
double area1;
double area2;
double area3;
cout << "Enter the name of the first friend: \0";
getline(cin, first);
cout << "Enter " << first << " pizza diameter : \0";
cin >> diameter;
cin.ignore();
radius = diameter / 2;
area1 = pi * radius * radius;
cout << "Enter the name of the second friend: \0";
getline(cin, second);
cout << "Enter " << second << " pizza diameter : \0";
cin >> diameter;
cin.ignore();
radius = diameter / 2;
area2 = pi * radius * radius;
cout << "Enter the name of the third friend: \0";
getline(cin, third);
cout << "Enter " << third << " pizza diameter : \0";
cin >> diameter;
radius = diameter / 2;
area3 = pi * radius * radius;
cout << showpoint << fixed << setprecision(1);
cout << " The area of " << first << "'s pizza is " << area1 << " inches squared\0" << endl;
cout << " The area of " << second << "'s pizza is " << area2 << " inches squared\0" << endl;
cout << " The area of " << third << "'s pizza is " << area3 << " inches squared\0" << endl;
if (area1 >= area2 && area1 >= area3) {
cout << first << " has the largest slice of pizza." << endl;
}
else if (area2 >= area1 && area2 >= area3) {
cout << second << " has the largest slice of pizza." << endl;
}
else {
cout << third << " has the largest slice of pizza" << endl;
}
cin.ignore();
cin.get();
return 0;
}
string presentStringPrompt(string) {
string value;
getline(cin,value);
return value;
cin.ignore();
}
double presentDoublePrompt(string) {
}
double computeAreaOfCircle(double) {
}