Thread: strange error int

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    7

    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

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> height = GetInteger();

    gg

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    7
    thanx

  4. #4
    Registered User
    Join Date
    Nov 2008
    Posts
    7
    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

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Use &#37;f to print a double (or a float).

    > radiussquared = (double)radiussquared;
    It's already a double, are you just making sure?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Don't use printf; use cout.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Is it C++, or merely just C code posted on the C++ forum?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Yeah, could have been either with
    if (whatShape == "cylinder")

    but then
    if (StringEqual(whatShape, "cylinder"))
    showed up and tipped the balance back towards C.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  10. #10
    Registered User
    Join Date
    Nov 2008
    Posts
    7
    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++

  11. #11
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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::.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with a strange for-loop problem
    By jasperleeabc in forum C++ Programming
    Replies: 4
    Last Post: 05-29-2009, 08:47 AM
  2. Strange results using dnsapi and windns
    By Niara in forum Networking/Device Communication
    Replies: 3
    Last Post: 08-13-2005, 10:21 AM
  3. Strange response from MSVC
    By VirtualAce in forum Game Programming
    Replies: 2
    Last Post: 04-17-2004, 07:40 AM
  4. strange edffect of "fputs"
    By Abdi in forum C Programming
    Replies: 1
    Last Post: 05-04-2002, 09:41 AM
  5. bcc32 compiling error (really strange!!)
    By jester in forum C++ Programming
    Replies: 14
    Last Post: 01-26-2002, 04:00 PM