Click here to Skip to main content
16,019,976 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
#include >iostream.h>
#include >conio.h>
struct student
{
char name[20];
int score;
char grade;
struct student* next;
};
typedef struct student student;
student* head,*current;
void main()
{
cout<<"enter std data \n";
cout<<"\n enter std name";
cin>>head->name;
cout<<"\n enter std grade";
cin>>head->grade;
head->next=Null;
cout<<"Do you want continue Y||N\t";
cin>>ans;
if(ans=='y')||(ans=='Y')
head->next=(student*);
malloc(sizeof(student));
void fillnode(struct student *w)
{
cout<<"\n enter std name";
cin>>w->name;
cout<<"\n enter std score";
cin>>w->score;
cout<<"\n enter std grade";
cin>>w->grade;
w->next=Null;
}
void createlist(struct student* head)
{
struct student*new=Null;
struct student*current=Null;
new=(student*)malloc(sizeof(student));
head=new;
current=new;
fillnode(head);
cout<<"do you want continue Y||N"

cin>.ans;

if(ans=='y')||(ans=='y')
{
if(___________)
{
do
new=(student*)malloc(sizeof(student));
current->next=new;
fillnode(new);
current=new;
cout<<"do you want to continue Y||N";
cin>>ans;
while(ans=='Y'||ans=='y')
}}
void printlist(student *h)
{
while(h!=Null)
{
cout<<"the name is"<<h->name;
cout<<"the score is"<<h->score;
cout<<"the grade is"<<h->grade;
h=h->next;
}
}
Posted
Updated 29-Jun-10 9:26am
v4
Comments
Kristian Sixhøj 29-Jun-10 13:32pm    
Reason for my vote of 1
"This code does not work, why?" is basically what you're asking. You need to provide more information and phrase your question better.
Aescleal 29-Jun-10 15:30pm    
I get the fact that you're still learning, but what you're writing is not particularly idiomatic C++ - it looks like C to me apart from the token uses of pre-standardisation IOStreams. If someone's charging you money for a C++ course based on this I'd suggest asking for a refund. If you're learning from a book then it's doing you no favours with it's teaching method. Chuck the book away and buy a copy of "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup instead, it's well worth the money.

This line is suspect:

cin>.ans;
 
Share this answer
 
Comments
[no name] 29-Jun-10 14:25pm    
thank u mr.simmons
is that is a only false in the code ???
because I am still a student
[no name] 29-Jun-10 14:25pm    
Reason for my vote of 5
good
I suppose you have to fill in something here:
if(___________)


Your first two includes needs to be corrected, using:
#include <file name here>



Edit: Lots of nice stuff

if(ans=='y')||(ans=='Y')
head->next=(student*);
malloc(sizeof(student));


Read up on how if-statements are to be written. The last malloc is dangling since it's preceded by a semi-colon.

Look at what the compiler tells you. Check each line in the error report, and compare to your literature and you will learn a lot faster.
 
Share this answer
 
v2
To add to this:

You open your Main, but never close it before starting a new method:
C
malloc(sizeof(student));
void fillnode(struct student *w)
{


C
if(ans=='y')||(ans=='y')

That is checking for the same things

When you do this:
C
head=new;
current=new;

you lose all reference to the actual head of the list since each student just contains a reference to the Next student, not the previous.

and, once again, you don't close off a method before starting a new one:
C
if(ans=='y')||(ans=='y')
{
if(___________)
{
do
//stuff
while(ans=='Y'||ans=='y')
}}
void printlist(student *h)


You're clearly floundering. You need to outline the different steps to begin with...as in
1.) Read in first student
2.) Ask if they want to continue
3.) Continue reading until they don't want to continue

Then, break that down into steps and code it out instead of just writing without having any clue what you're trying to do.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900