C ++中的代码无法运行,我不知道结果,我需要帮助 [英] that code in c++ not run and i don't know the result and i need help

查看:104
本文介绍了C ++中的代码无法运行,我不知道结果,我需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#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;
}
}

推荐答案

此行是可疑的:

This line is suspect:

cin>.ans;


我想您必须在这里填写一些内容:
I suppose you have to fill in something here:
if(___________)



您需要对前两个包含的内容进行更正,方法是:



Your first two includes needs to be corrected, using:

#include <file name here>




很多不错的东西




Lots of nice stuff

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



阅读有关如何编写if语句的信息.最后一个malloc悬空了,因为它前面是分号.

查看编译器告诉您的内容.检查错误报告中的每一行,并与您的文献进行比较,您会学到很多东西.



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.


添加到此:

您打开Main,但是在开始新方法之前永远不要关闭它:
To add to this:

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





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


那是在检查相同的东西

执行此操作时:


That is checking for the same things

When you do this:

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:

if(ans=='y')||(ans=='y')
{
if(___________)
{
do
//stuff
while(ans=='Y'||ans=='y')
}}
void printlist(student *h)



你显然在挣扎.您需要概述从...开始的不同步骤,如
1.)阅读第一个学生
2.)询问他们是否要继续
3.)继续阅读,直到他们不想继续

然后,将其分解为多个步骤并进行编码,而不是仅仅编写而不知道您要做什么.



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.


这篇关于C ++中的代码无法运行,我不知道结果,我需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆