Thread: What is wrong with this C++ code?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Guest
    Guest
    Code:
    exercise2.cpp:17:19: error: C++ requires a type specifier for all declarations
      void read_ages(&name, n) // member function
                      ^
    exercise2.cpp:17:25: error: unknown type name 'n'
      void read_ages(&name, n) // member function
    The error tells you in no unspecific terms what's wrong. It just doesn't make sense that you're struggling with this while writing methods - this is a running before walking scenario. That's why I asked if you're coming from another language and jumped into this head first.

    What you may have wanted is something like:
    Code:
    void read_ages(const std::string& name)
    {
        names_vec.push_back(name);
        double age;
        cout << "Please enter an age for " << name << endl;
        cin >> age;
        ages_vec.push_back(age);
    }
    But that wouldn't actually help you because there are several other problems waiting and they're due to not being familiar with certain concepts yet. Nobody can fill that gap except you.
    Last edited by Guest; 11-07-2019 at 05:22 PM. Reason: formatting

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What's wrong with this C code?
    By sunil9211 in forum C Programming
    Replies: 1
    Last Post: 05-12-2018, 12:58 AM
  2. What's wrong with this code?
    By andysalter in forum C Programming
    Replies: 2
    Last Post: 04-03-2013, 05:37 AM
  3. what is wrong in my code?
    By rac1 in forum C Programming
    Replies: 12
    Last Post: 12-25-2011, 02:58 PM
  4. what is wrong with this code please
    By korbitz in forum Windows Programming
    Replies: 3
    Last Post: 03-05-2004, 10:11 AM
  5. What's wrong with this code???
    By /\/\ E /\/ @ in forum C++ Programming
    Replies: 1
    Last Post: 07-25-2002, 12:55 AM

Tags for this Thread