-
strange error int
here is my code
Code:
#include <stdio.h>
#include "genlib.h"
#include "simpio.h"
#define pi 3.14
int main() {
string whatShape;
printf("enter the shape: ");
whatShape = GetLine();
if (whatShape == "box")
{
int width, length, height, ansr;
printf("enter width: ");
width = GetInteger();
printf("enter height: ");
height = GetInteger;
printf("enter length: ");
length = GetInteger;
ansr = height * length * width;
printf("The voulme of the box is: %d ", ansr);
}
if (whatShape == "cube")
{
int side, ansr;
printf("enter the length of a side: ");
side = GetInteger();
ansr = side * side * side;
printf("The volume of the cube is: %d", ansr);
}
if (whatShape == "cylinder")
{
double radius, radiussquared, height, ansr;
printf("enter the height: ");
height = GetInteger();
height = (double)height;
printf("enter the radius: ");
radius = GetInteger();
radiussquared = radius * radius;
radiussquared = (double)radiussquared;
ansr = radiussquared * height * pi;
printf("The volume of the cylinder is: %d", ansr);
}
else printf("that is not a box, cude, or cylinder");
}
error
Code:
: error C2440: '=' : cannot convert from 'int (__cdecl *)(void)' to 'int'
There is no context in which this conversion is possible
i have no idea what to do to fix this, any help would be greatly appreciated
-
>> height = GetInteger();
gg
-
-
now i have worked it out a little but im getting a strange error here:
Code:
if (StringEqual(whatShape, "cylinder"))
{
double radius, radiussquared, height, ansr, pi;
int radius1, height1;
pi = 3.14;
printf("enter the height: ");
height1 = GetInteger();
height = (double)height1;
printf("enter the radius: ");
radius1 = GetInteger();
radius = (double)radius1;
radiussquared = radius * radius;
radiussquared = (double)radiussquared;
ansr = radiussquared * height * pi;
printf("The volume of the cylinder is: %d\n", ansr);
}
with height 3 and radius 3 i get this answer: -2061584302
-
Use %f to print a double (or a float).
> radiussquared = (double)radiussquared;
It's already a double, are you just making sure?
-
Don't use printf; use cout.
-
Is it C++, or merely just C code posted on the C++ forum?
-
Right. I saw "string" in there, but it is apparently C since <string> has not been included, so I'm assuming it is a typedef for char.
But then again, maybe one of those headers include it because the error message is typical C++-ish...
So that's a very good question.
-
Yeah, could have been either with
if (whatShape == "cylinder")
but then
if (StringEqual(whatShape, "cylinder"))
showed up and tipped the balance back towards C.
-
it is c++, the first code posted contained quite a few errors, ive had to add <string> thank you for the help.
MS visual c++
-
Hrm...
Then how about you replace all the printf-s with cout and post a complete list of errors?
If there are any left, that is.
And you probably should add "using namespace std;" or qualify string and cout with std::.