-6
\$\begingroup\$

I'm getting these errors:

error C2512: 'course' : no appropriate default constructor available
error C2374: 'co' : redefinition; multiple initialization

#include <stdafx.h>
#include <iostream>
#include <string>
using namespace std;
class course
{
    string coursename;
    int courseid;
    int passinggrade;
public:
    course( string acoursename, int acourseid, int apassinggrade ) //consturctor
    {
        coursename=acoursename;
        courseid=acourseid;
        passinggrade=apassinggrade;
    }
    string getcoursename()
    {
        return coursename;
    }
    int getcourseid()
    {
        return courseid;
    }
    int getpassinggrade()
    {
        return passinggrade;
    }
};
int main()
{
    string x;
    int id;
    int pg;
    course co;
    cout<<"what is the course name \n";
    cin>> x;
    cout<<"what is the course id \n";
    cin>>id;
    cout<<"what is the passing grade \n";
    cin>>pg;
    course co(x, id, pg);
    course co1;
    cout<<"what is the course name \n";
    cin>> x;
    cout<<"what is the course id \n";
    cin>>id;
    cout<<"what is the passing grade \n";
    cin>>pg;
    course co1(x, id, pg);
    //cout <<"the course name is "<<co.coursename(x)<<" \n" <<"the course id is "<<co.courseid(id)<<" \n" <<"the course id is "<<co.passinggrade(pg);
    system("pause");
    return 0;
 }
\$\endgroup\$
  • 1
    \$\begingroup\$ Welcome to Code Review! I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. Code Review is not the site to ask for help in fixing or changing what your code does. Once the code does what you want, we would love to help you do the same thing in a cleaner way! Please see our help center for more information. \$\endgroup\$ – SuperBiasedMan Nov 4 '15 at 12:32
1
\$\begingroup\$
  1. You don't have a default constructor, so you can't just course co; you have to define a default constructor first, see here.

  2. On line 42 you are defining co again.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.