#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
const float pi=3.14;
const float e=2.71828;
int main()

    int r,h;
    double A,E1,E2;
    cout<< "please enter two positive integers for r and h: "<<endl;
    cin>>r>>h;
    A=(2*pi*r*r+2*r*r*h);
    E1=(pow(e,h))+(3*(log10(A)));
    E2=sqrt(abs(cos(pow(r,2.0)+sin(pow(r,2.0)));
    cout<<"Radius      Height      Area      E1      E2"<<endl;
    cout<<fixed<<setprecision(2)<<showpoint;
    cout<<"======      ======      ====      ==      =="<<endl;
    cout<<setw(6)<<r<<setw(12)<<h<<setw(10)<<A<<setw(8)<<E1<<setw(8)<<E2<<endl;

    return 0;
}

Error list:

Warning 1 warning C4305: 'initializing' : truncation from 'double' to 'const float'
Warning 2 warning C4305: 'initializing' : truncation from 'double' to 'const float'

what could i do ?

Edited 1 Year Ago by sunshine102030

Attachments 2.PNG 85.8 KB 1.PNG 23.73 KB
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
const float pi=3.14;
const float e=2.71828;
int main()
{
    float r,h;
    double A,E1,E2;
    cout<< "please enter two positive integers for r and h: "<<endl;
    cin>>r>>h;
    A=(2*pi*r*r+2*r*r*h);
    E1=(pow(e,h))+(3*(log10(A)));
    E2=sqrt(abs(cos(r*r)+sin(r*r)));
    cout<<"Radius      Height      Area      E1      E2"<<endl;
    cout<<fixed<<setprecision(2)<<showpoint;
    cout<<"======      ======      ====      ==      =="<<endl;
    cout<<setw(6)<<int(r)<<setw(12)<<int(h)<<setw(10)<<A<<setw(8)<<E1<<setw(8)<<E2<<endl;

    return 0;
}

I made these changes and i think it is correct , but they ask us to convert r^2 in the functions sin and cos to radians
so who i can do that ?

Edited 1 Year Ago by sunshine102030

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
const float pi=3.14;
const float e=2.718281828;
int main()
{
    float r,h;
    double A,E1,E2;
    float rad;
    cout<< "please enter two positive integers for r and h: ";
    cin>>r>>h;
    A=(2*pi*r*r)+(2*pi*r*h);
    E1=(pow(e,h))+(3*(log10(A)));
    rad=((r*r)*pi)/180;
    E2=sqrt(abs(cos(rad)+sin(rad)));
    cout<<endl;
    cout<<"  Radius      Height      Area      E1      E2"<<endl;
    cout<<   fixed<<setprecision(2)<<showpoint;
    cout<<"  ======      ======      ====      ==      =="<<endl;
    cout<<   setw(8)<<int(r)<<setw(12)<<int(h)<<setw(10)<<A<<setw(8)<<E1<<setw(8)<<E2<<endl;
    cout<<"  ============================================"<<endl;
    return 0;
}

i solve the problem , thanks.

Try
const double pi=3.14;
const double e=2.718281828;
instead. That's what ddanbe was trying to tell you.

Edited 1 Year Ago by rubberman

This article has been dead for over six months. Start a new discussion instead.