我怎样才能成功完成我的程序 [英] How can I successfully make my program work

查看:73
本文介绍了我怎样才能成功完成我的程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您在大学工作,并且部门负责人为您分配了编写C ++程序的任务,该程序允许学生注册课程。该计划还应在每次注册后更新课程信息,并向学生发布课程表。学生最多可以注册两门课程。如果学生输入字母f或参加两门课程后,课程结束。假设打开了三个课程和他们的信息。



当我打开课程并输入课程名称和id没有任何反应时我也无法更新课程。< br $> b $ b

我的尝试:



#包括<&的iostream GT; 
#include< fstream>
#include< string>
#include< iomanip>
using namespace std;
int main()
{
string course_name,u_course_name,a,b,c,d;
int u_courseID,courseID,maxnbr,nbenrolled,count,i;
char y;
count = 0;
i = 0;
ifstream infile;
infile.open(courses.txt);
if(!infile)
{
cout<<error<< endl;
返回0;
}
infile>> courseID>> course_name>> maxnbr>> nbenrolled;
infile>> courseID>> course_name>> maxnbr>> nbenrolled;
for(i = 0; infile,i< 3; i ++)
{
cout<<请在表格中输入您的选择(courseID,coursename)<< endl ;
cin>> y>> u_courseID>> y>> u_course_name>> y;
infile>> courseID>> course_name>> maxnbr>> nbenrolled;
while(count< 2)
{
if((u_courseID =='f')||(y =='f')||(u_course_name ==f))
{
cout<<程序正在终止....;
返回0;
}
else if((courseID == u_courseID)&&(course_name == u_course_name)&&(nbenrolled< maxnbr))
{
cout<< ;您已注册参加以下课程<<< endl<< setw(18)<<**********<< endl<<
courseID:<< courseID<< setw(25)<<<课程名称:<<< course_name<< endl;
nbenrolled ++;
count ++;
}
else if((courseID == u_courseID)&&(course_name == u_course_name)&&(maxnbr == nbenrolled))
{
cout< <此课程已满<< endl;
}
i ++;
}
}
返回0;
}

解决方案

所以使用调试器找出发生了什么!

你我可能会发现 cin 行停在它的位置:

 cin>> y>> u_courseID>> y>> u_course_name>> y; 

为什么?

因为它要求五个输入,而你可能只给出了你要求的两个输入。 ..


You are working in a university, and the head of the department assigned to you the task of writing a C++ program that allows students to enroll in courses. The program should also update courses information after each enrollment, and issue the course table to the student. The student can enroll in maximum two courses. The program ends if the student entered the letter f or after enrolling in two courses. Assume that three courses are opened and their information.

when i open the program and input the course name and id nothing happen i also couldn't update the courses.

What I have tried:

#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
using namespace std;
int main()
{
    string course_name,u_course_name,a,b,c,d;
    int u_courseID,courseID,maxnbr,nbenrolled,count,i;
    char y;
    count=0;
    i=0;
    ifstream infile;
    infile.open("courses.txt");
    if(!infile)
    {
        cout<<"error"<<endl;
        return 0;
    }
    infile>>courseID>>course_name>>maxnbr>>nbenrolled;
    infile>>courseID>>course_name>>maxnbr>>nbenrolled;
    for  (i=0;infile,i<3;i++)
    {
        cout<<"please enter your choice in the form ( courseID , coursename )"<<endl;
        cin>>y>>u_courseID>>y>>u_course_name>>y;
        infile>>courseID>>course_name>>maxnbr>>nbenrolled;
        while(count<2)
        {
            if((u_courseID=='f') || (y=='f') || (u_course_name =="f"))
            {
                cout<<"Program is terminating....";
                return 0;
            }
            else if((courseID==u_courseID) && (course_name==u_course_name) && (nbenrolled<maxnbr))
            {
                cout<<"you are enrolled in the following course"<<endl<<setw(18)<<"**********"<<endl<<
"courseID : "<<courseID<<setw(25)<<"course name : "<<course_name<<endl;
                nbenrolled++;
                count++;
            }
            else if((courseID==u_courseID) && (course_name==u_course_name) && (maxnbr==nbenrolled))
            {
                cout<<"this course is full"<<endl;
            }
            i++;
        }
    }
    return 0;
}

解决方案

So use the debugger and find out what is going on!
You'l probably find that the cin line is where it stops:

cin>>y>>u_courseID>>y>>u_course_name>>y;

Why?
Because it's asking for five inputs, and you are probably only giving the two you asked for...


这篇关于我怎样才能成功完成我的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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