+ 3
Problem in C++ programs while executed ( some body help me to solve this problem)
syntax is correct and all is well but no output... class Student{ char *name, gender; int age, i; float m[5]; double avg, tot; public : Student (){ i=0; } void getDetail(){ int j=-1; std::cin>>name; std::cin>>age; std::cin>>gender; while(j<5){ std::cin>>m[++j]; } } void calc(){ tot=m[0]+m[1]+m[2]+m[3]+m[4]; avg=tot/5;
7 Answers
+ 5
hello swim~ code is this : đ
//logic may be correct but some linker problem....
#include <iostream>
#include <conio.h>
class Student{
char *name, gender;
int age, i;
float m[5];
double avg, tot;
public :
Student (){ i=0;}
void getDetail(){
int j=-1;
std::cin>>name;
std::cin>>age;
std::cin>>gender;
while(j<5){
std::cin>>m[++j];
}
}
void calc(){
tot=m[0]+m[1]+m[2]+m[3]+m[4];
avg=tot/5;
}
void putDetail(){
std::cout<<name<<"\n";
std::cout <<age<<"\n";
std::cout<<gender<<"\n";
std::cout <<tot<<"\n";
std::cout<<avg<<"\n";
}
};
int main() {
Student s[10];
int i;
for(i=0;i<1; i++)
s[i].getDetail();
for(i=0;i<1; i++)
s[i].calc();
for(i=0;i<1; i++)
s[i].putDetail();
getch();
return 0;
}
+ 5
@swim I accept your suggestion.. but at the same time we use turbo c++ compiler as a practice only just handout ... and char *name is not a pointer in the point of time in that program it is a character string....
Thanks :)
+ 4
@sunil raj sir, I think that the given inputs in this program are overloaded in the code player, In turbo c++ compiler we give the inputs in the run time, but here we give the overall inputs at the same time. so the code player takes overload., so it may be cause for that linker problem
+ 3
thank you Swim & Mr. Kumaresan, for your valuable suggestions.