Hi gurus,
kindly help me in tracking these errors. The purpose of the program is to calculate the area and circumference of a circle using struct. the details stored are its name, radius, area and circumference. thank you

#include <iostream>
#include <iomanip>
#include<cmath>

using namespace std;

struct circle {

  
  int radius;
  float circumference;
  float area;

    float compute_area()
    {
        area = (radius*radius* 3.14);
        return(area);
    }

float compute_circumference()
{
	circumference=(2*radius*3.14);
	return (circumference);
}


 main(int) {
string name;
    circle test;
    char reply;


do {
    cin.ignore(80);
    system("cls");
    cout << "Enter the name of the Circle          : ";
    getline(cin,test.name);
    cout << "Enter the given Radius of the Circle  : ";
    cin >> test.radius;

    
    cout << "\nThe Area of the Circle is  : ";
    cout<< test.compute_area() << test.compute_circumference();
   cout << "\n\n";
   cout << "Do you want to continue y/n : ";
    cin >> reply;
    if (toupper(reply) == 'N') {
        cout << "\n\n";
        cout << "\t\t Thank You For Using This Software !!!";
        break;
    }
    } while (toupper(reply!='Y'));
    cout << "\n\n";
    system("pause");
	
}

Recommended Answers

All 4 Replies

Program: Enter the name of the Circle

User Commits suicide

Structurally the program makes no sense. main() is embedded inside circle, and circle isn't properly terminated. name is a variable local to main() but it's being used as a member of circle.

This compiles, but I didn't run it:

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

struct circle
{
    string name;
    int radius;
    float circumference;
    float area;

    float compute_area()
    {
        area = (radius*radius* 3.14);
        return(area);
    }

    float compute_circumference()
    {
        circumference=(2*radius*3.14);
        return (circumference);
    }
};

int main()
{
    circle test;
    char reply;

    do
    {
        cin.ignore(80);
        cout << "Enter the name of the Circle          : ";
        getline(cin,test.name);
        cout << "Enter the given Radius of the Circle  : ";
        cin >> test.radius;
        cout << "\nThe Area of the Circle is  : ";
        cout<< test.compute_area() << test.compute_circumference();
        cout << "\n\n";
        cout << "Do you want to continue y/n : ";
        cin >> reply;
        if (toupper(reply) == 'N')
        {
            cout << "\n\n";
            cout << "\t\t Thank You For Using This Software !!!";
            break;
        }
    }
    while (toupper(reply!='Y'));
    
    cout << "\n\n";
}

Whats wrong with this line.Returning an error C2065: 'getline' : undeclared identifier

getline(cin,test.name);

Whats wrong with this line.Returning an error C2065: 'getline' : undeclared identifier

getline(cin,test.name);

Ah, the code shouldn't compile, maybe my compiler's settings aren't strict enough. :D This error means that there's no #include <string> directive. That's where the version of getline() that works with std::string is declared.

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.