本文介绍了我在做什么错误的C ++编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 读入学生的姓氏,gpa和大学生获得的小时数。如果他们已经赚了0个小时,那么打印新学生,如果他们已经至少1小时但不到32岁,则打印新生,32到60岁,大二学生61到90岁,大三学生和90岁以上大四学生。如果它们超过3.2 gpa并且在下一个5小时内,则将它们移动。 (不要让新生升级)你的程序应适用于任意数量的数据。 我尝试过: #include < iostream > #include < iomanip > 使用 namespace std; int main() { char 名称; double gpa; int 小时; while (cin>> name>> gpa>>小时) { if (小时== 0 ) { cout<< 新学生<< name<< <<< hours<< << GPA<< ENDL; } else if ((hours == 1 )&&(小时< 32)) { if ((gpa> 3。 2 )&&(小时+ 5 )) cout<< 新生<< name<< << hours<< endl; cout<< 大二<< gpa<< endl; } else if ((hours == 32 )&&(小时< = 60 )) { if ((gpa> 3。 2 )&&(小时+ 5 )) cout<< 大二<< name<< << hours<< endl; cout<< Junior<< gpa<< endl; } else if ((hours == 61 )&&(小时< = 90 )) { if ((gpa> 3。 2 )&&(小时+ 5 )) cout<< Junior<< name<< << hours<< endl; cout<< Senior<< gpa<< endl; } 其他 如果(小时> 90) { cout<< Senior<< name<< << hours<< << gpa<< endl; } } 解决方案 您应该学习尽快使用调试器。而不是猜测你的代码在做什么,现在是时候看到你的代码执行并确保它完成你期望的。 调试器允许你跟踪执行逐行检查变量,你会看到它有一个停止做你期望的点。 调试器 - 维基百科,免费的百科全书 [ ^ ] 掌握Visual Studio 2010中的调试 - A初学者指南 [ ^ ] Read in the a students last name , gpa and the number of hours a college student has earned. If they have earned 0 hours, then print new student, if they have eared at least 1 hour but less than 32, print freshman, 32 to 60, sophomore 61 to 90, junior and over 90 a senior. If they have over a 3.2 gpa and are within 5 hours of the next then move them up. ( Do not move up new students) Your program should work for any number of lines of data.What I have tried:#include<iostream>#include<iomanip>using namespace std;int main(){ char name; double gpa; int hours; while(cin>>name>>gpa>>hours) { if( hours ==0) { cout<<" New Student "<<name<<" "<<hours<<" "<<gpa<<endl; }else if(( hours ==1) &&(hours <32)) { if((gpa >3.2)&&(hours + 5)) cout<<" Freshman "<<name<<" "<<hours<<endl; cout<<" Sophomore "<<gpa<<endl; }else if(( hours ==32) &&(hours <=60)) { if((gpa >3.2) && (hours + 5)) cout<<" Sophomore "<<name<<" "<<hours<<endl; cout<<" Junior "<<gpa<<endl; }else if(( hours ==61)&& (hours <=90)) { if((gpa >3.2) &&(hours + 5)) cout<<" Junior "<<name<<" "<<hours<<endl; cout<<" Senior "<<gpa<<endl; }else if(hours >90) { cout<<" Senior "<<name<<" "<<hours<<" "<<gpa<<endl; }} 解决方案 You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.Debugger - Wikipedia, the free encyclopedia[^]Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^] 这篇关于我在做什么错误的C ++编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-18 16:54