Results 1 to 34 of 34

Thread: Dev C++ not compiling

  1. #1

    Thread Starter
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037

    Dev C++ not compiling

    #include<iostream>
    inline float cube(const float s) {return s*s*s;}
    int main() {

    float side;
    cin >> side;
    cout << "Volume of cube with side" << side<< "is "
    << cube(side) << endl;

    return 0;
    }

    Shouldn't that compile? I can't compile anything!! I just downloaded the new version today and it does the same thing as the old. I can't compile. Am I missing something?

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    You're missing a using namespace std; in there.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037
    Didn't learn about those yet. If that is object oriented, I haven't even touched it yet.

    What should I type in?

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Simply add the line

    using namespace std;

    after all your includes.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037
    #include<iostream>
    using namespace std;
    inline float cube(const float s) {return s*s*s;}
    int main() {

    float side;
    cin >> side;
    cout << "Volume of cube with side" << side<< "is "
    << cube(side) << endl;

    return 0;
    }

    Still didn't work.

  6. #6
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    I always like to call namespaces some sort of collections of functions, nicely ordered in different namespaces.

    In this case, it's about the std namespace.
    Normally you would type
    Code:
    #include<iostream> 
    inline float cube(const float s) {return s*s*s;} 
    int main() { 
    
    float side; 
    std::cin >> side; 
    std::cout << "Volume of cube with side" << side<< "is " 
    << cube(side) << endl; 
    
    return 0; 
    }
    The std:: indicates that the function you're going to call is in the std namespace.

    Now the using namespace ... means that the compiler assumes those functions are in the std namespace.

    so:
    Code:
    #include<iostream> 
    using namespace std;
    
    inline float cube(const float s) {return s*s*s;} 
    int main() { 
    
    float side; 
    cin >> side; 
    cout << "Volume of cube with side" << side<< "is " 
    << cube(side) << endl; 
    
    return 0; 
    }
    Would work since the compiler knows those cin and cout are in the std namespace.

    I hope I clarified things a bit!
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  7. #7

    Thread Starter
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037
    It still does not compile.

  8. #8
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    What errors do you get than my friend? going to eat now but I'm sure there are other people that are able to help you out!
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  9. #9

    Thread Starter
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037
    Compiler: Default compiler
    Building Makefile: "D:\Program files\Dev-Cpp\Makefile.win"
    Executing make...
    make.exe -f "D:\Program files\Dev-Cpp\Makefile.win" all
    g++.exe -c Templates/main.cpp -o Templates/main.o

    Templates/main.cpp:1:20: iostream: No such file or directory
    Templates/main.cpp: In function `int main(int, char**)':
    Templates/main.cpp:9: `cin' undeclared (first use this function)

    Templates/main.cpp:9: (Each undeclared identifier is reported only once for
    each function it appears in.)

    Templates/main.cpp:10: `cout' undeclared (first use this function)
    Templates/main.cpp:11: `endl' undeclared (first use this function)

    make.exe: *** [Templates/main.o] Error 1

    Execution terminated

  10. #10
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Is this the newest available version of DevC++? If not, get the newest. If yes then your include paths are probably set up incorrectly. I'm sure someone here can help you with that (I've never used DevC++).
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  11. #11

    Thread Starter
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037
    Isn't there a standard that compilers follow.

  12. #12
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    The latest version 5 is still in beta, I believe.

    Maybe it is a bug or something.

    That's why I'm still using version 4.

  13. #13
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Standard in what way? C++ and it's libraries are standardized, the include paths are not.

    And the standard changed a few years ago, so older compilers don't know the <iostream> header.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  14. #14

    Thread Starter
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037
    I should not have an old compiler. It is Dev C++ beta 5.

  15. #15
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Maybe you should try degrading to version 4 as transcender is doing? Check if that helps..
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  16. #16

    Thread Starter
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037
    I have 4 now but I am having another problem. It does not seem to recognize endl; or setw (5); Here is the whole thing: It compiles with no errors but does not display right.

    #include <cstdlib>
    using namespace std;
    #include <iostream>
    using namespace std;
    #include <iomanip.h>
    using namespace std;
    int main(){

    const int R=10, F=11;
    int responses [R]={1, 4, 6, 4, 8, 2, 6, 1, 8, 4};
    int frequency [F]={0};

    for (int answer=0; answer < R; answer++)
    ++frequency [responses[answer]]; // This is the key to it all!!!
    cout << "Number" << setw(18) << "Frequency" << endl;

    for (int rating=1; rating < F; rating++)
    cout<< rating << setw(11) << frequency[rating] << endl; system("PAUSE"); return 0;}
    Last edited by aewarnick; Jan 6th, 2003 at 10:42 PM.

  17. #17

    Thread Starter
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037
    I found out what was wrong: I needed this as main arguments:

    int argc, char *argv[]

    What are they?

  18. #18
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    First, iomanip too is one of the standard headers, so it should be <iomanip>. <iomanip.h> and <iostream> don't work together.

    Well, if you call an app like this:
    myapp hello there -version -verbose

    then you are passing command line arguments. Those arguments are in argc and argv. argc is the number of arguments and argv are the actual arguments. In this case argc would be 5 and argv would be
    {"myapp", "hello", "there", "-version", "-verbose"}
    because the actual program name is always included in the arguments.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  19. #19
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    I think the supposed behaviour is for argv[0] to be the program name as it was invoked. For example, on a Unix system, if it is called via a symbolic link, or on any system if you gave it the pathname to the program, or whatever
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  20. #20

    Thread Starter
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037
    I guess I will learn more about that later.

    Here is my problem now: I can't get that to break when a negative number is entered. Did I do something wrong?

    for (int i=0; i<R; i++){
    cin >> responses[i];
    if (responses[i]<0) break;}

  21. #21
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Please use [code][/code] tags when posting code and format it properly.

    Code:
    for (int i=0; i<R; i++) {
      cin >> responses[i];
      if (responses[i]<0)
        break;
    }
    Looks ok to me. It doesn't break?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  22. #22

    Thread Starter
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037
    Now it breaks. Take a look at my other post about illegal operations. It came from there. All I changed was putting a limit in my arrays.

    Would it be ok to use a letter instead of a number?
    Last edited by aewarnick; Jan 7th, 2003 at 10:57 AM.

  23. #23
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    For what?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  24. #24

    Thread Starter
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037
    this
    cin >> responses[i]; if (responses[i]<=-1) break;
    to this
    cin >> responses[i]; if (responses[i]<=d) break;

  25. #25
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    try
    Code:
    cin >> responses[i]; if (responses[i]<='d') break;
    please always post your code here inbetween code tags [code] Code here! [/code]
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  26. #26
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I seldom use code tags for one line, and for multiple lines I already told him.

    Whatever, you can do it, but the outcome won't be what you expect. A
    int i;
    cin >> i;
    will only accept numbers as input, else cin will enter a fail state where it won't read anything anymore.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  27. #27

    Thread Starter
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037
    Ok, but I read in my book that letters have integer values and what does putting 'd' around d do?

  28. #28
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Well, d would be a variable named d. 'd' is the letter d.

    Yes, letters have integer values (their indices in the ASCII or other code tables). I said you could do it, but I said it wouldn't be what you expect.

    I should rephrase.
    int i;
    cin >> i;
    will only accept digits as input.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  29. #29

    Thread Starter
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037
    What you mean is that if I try to use the number value of a letter and trying to add that letter to a number it will not work but,

    This line is ok though, right?

    cout << "Enter d when finished. Next score: "; cin >> score[i];
    if (score[i]==d ||!(score[i]<1000001)) break;
    Last edited by aewarnick; Jan 8th, 2003 at 11:11 AM.

  30. #30
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Is score a string? if it's an int it won't work as CB said...
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  31. #31
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    No, the compiler will assume d is a variable. And if you write
    'd'
    then the user has to enter the ASCII code of 'd' in order to stop the loop.

    Look, it's as simple as that:
    int i;
    cin >> i;
    reads in the string representation of a number and then converts it to that number. So it might for example read in "123" and then convert that to the number 123. Look at the source code for the itoa function if you want to know how that works.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  32. #32

    Thread Starter
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037
    I made d a char and without the ' ' it works perfect. With them it loops endlessly. It did the same exact thing as an int with the ' ' but without them worked perfect.
    But. . . as an int are you saying that if the user enters in d's # representation that it will inturpret it as d and break.

  33. #33
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Code:
    int i=0;
    while(i != 'd')
    {
      cin >> i;
    }
    This loop will stop when the user enters
    100
    which is the ASCII code of 'd'
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  34. #34

    Thread Starter
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037
    Good example. Got it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width