Menu

comping error

2009-08-28
2012-09-26
  • ryan jennens

    ryan jennens - 2009-08-28

    I'm enrolled in an online class and I'm trying to figure this out as an assignment

    Is there anything wrong with this code? I've made it from scratch but it keeps coming up with errors!

    // number two on review 1.2

    include <iostream>

    include <string>

    // variables

    int num_Values;
    float score;
    long double size (16.34);
    char flag (t);

    // strings

    int main ()
    {
    string name = "William";
    cout << name << endl;
    system("pause");
    return 0;
    }

     
    • cpns

      cpns - 2009-08-28

      > but it keeps coming up with errors!

      Good! Read them, they will tell you what the problem is. That is what they are for. If you want help understanding them (which is fair enough), then post them. Learning to understand and interpret the error messages will be much more useful to you in the long term that just getting an answer to this specific question.

      While function-like initialisation of basic types may work in C++ it is not very common to do that. I would generally avoid declaring a variable "long double" unless you know:

      a) that you really need that level of precision,
      b) that every compiler you will ever build your code with recognises the type,
      c) that your compiler actually uses higher precision than for plain double (not all do, if you code relies on it, it will not be portable, and may fail).

      The variable t does not exist where you have used it as an initialiser.

      Read up on namespaces, and the std:: namespace in particular.

      Clifford

       
    • ryan jennens

      ryan jennens - 2009-08-28

      Sorry, it should be compiling!

       
    • Wayne Keen

      Wayne Keen - 2009-08-28

      Please post your Basic 3. They are covered in the thread with the appropriate
      title "Please Read Before Posting a Question"

       
      • Wayne Keen

        Wayne Keen - 2009-08-28

        One thing by the way that screams from your code. You are using functions
        that are in the standard namespace, but you I see nothing like

        using namespace std;

        or qualifiers like

        std::cout

        Wayne

         
    • Wayne Keen

      Wayne Keen - 2009-08-28

      And what do you thing this line of code is doing?

      char flag (t);

       
    • Wayne Keen

      Wayne Keen - 2009-08-28

      And note that the "system" function shoows up in

      cstdlib

      In short, no, your code should NOT compile, it has signiificant errors.

      With the namespace problem addressed, the weird char line commented out, and cstdlib included, you code compiles and runs here.

      Wayne

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.