[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 187
  • Last Modified:

output

This is a sample C++ program that I found. I wanted to compile it to see if I could get to run, but I encountered some errors. I typed the program exactly as it appeared, but it doesn't work.

#include<iostream.h>
#include<string.h>
class student
{
public:
char fname[10],lname[15],major[10];
float semhours,credits;
void add_s(char *fn,char *ln,char *maj,float horus,float creds)
{
strcpy(fname,fn);
strcpy(lname,ln);
strcpy(major,maj);
semhours=hours;
credits=creds;
}
void show_info()
{
float gpa;
gpa=credits/semhours;
cout<<fname<<""<<lname<<"GPA:"<<gpa;
cout<<"Major:"<<major<<endl;
}
void addcourse(char xgrade,float hours)
{
float gpa;
if (xgrade=='a')credits=credits+(hours*4);
else if (xgrade=='b')credits=credits+(hours*3);
else if (xgrade=='c')credits=credits+(hours*2);
else if (xgrade=='d')credits=credits+(hours*1);
else credits = credits +0;
semhours = semhours + hours;
gpa = credits/semhours;
cout<<"Added course for "<<fname<<""<<lname;
cout<<"New GPA:"<<gpa<<endl;
}
};
int main (void)
{
student jane,john;
jane.add_s("Jane","Smith","Math",6,12);
john.add_s("John","Doe","English",9,28);
jane.show_info();
jane.addcourse('a',3);
john.show_info();
john.addcourse('c',3);
return 0;
}

A:\student.cpp(13) : error C2065: 'hours' : undeclared identifier
A:\student.cpp(13) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
0
cbrookhart
Asked:
cbrookhart
  • 2
1 Solution
 
_lychee_Commented:
u misspelt hours in ur function declaration as horus... that's the only mistake i can see from ur compile errors...

have fun! :)
0
 
cbrookhartAuthor Commented:
Thanks. I didn't see that spelled hours wrong.
0
 
_lychee_Commented:
whenever u get these undeclared identifier thingies i think most of the time (for me at least :>) it's due to some spelling error or another... just keep that in mind ok?
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now