Monday, 9 September 2013

C++ Beginner, [Warning] converting to `int' from `double'

C++ Beginner, [Warning] converting to `int' from `double'

I'm having a hard time trying to get this simple program to run without
error. How do you get the return type to come back as a double for this
expression: a = 2 * NUM + z;. Probably a super noob question lol but any
help is appreciated, thanks in advance.
#include <iostream>
using namespace std;
int main()
{
const int NUM = 10;
const double x = 20.5;
int a, b;
double z;
char grade;
a = 25;
cout <<"a = " <<a <<endl;
cout <<" Enter two integers : ";
cin >> a >> b;
cout << endl;
cout << " The numbers you entered are "
<<a <<" and " <<b <<endl;
z = x + 2 * a - b;
cout <<"z = " <<z <<endl;
grade = 'A';
cout <<"Your grade is " <<grade <<endl;
a = 2 * NUM + z;
cout << "The value of a = " << a <<endl;
return 0;
}

No comments:

Post a Comment