问题描述
嘿各位新人,2周前我开始学习编程,我正在研究一些项目形式书学习用C ++编写的书,看起来这本书中的一些代码已经过时了(试着在互联网上找到解决方案,但一切看起来都一样......)。所以我有for循环的问题。当我执行程序时,它显示1条消息,用户需要回答是,之后显示消息2但是程序没有等待用户输入值而是程序执行来自FOR循环的下一条消息并结束程序(该消息应该被执行)只有学生编号无效)。
执行时程序的样子:
Hey guys in new here and i started to learn programming 2 weeks ago and i was working on some project form book Learn programming with C++ book and looks like some of the code in that book is outdated(Tryed to find on the internet solution but everything looks the same ... ). So i have problem with for loops. When i execute program it show 1 message and user need to answer with yes and after that it show message 2 but program doesnt wait user to enter "value" instead program execute next message from FOR loop and end the program(That message should be executed only if student number was invalid ).
How program looks like when executed:
Do you want to calculate the grade ? : YES
Enter student type " << "(1-English, 2-Math,3-Sience):Please enter valid number...
Process returned 1 <0x1> execution time ...
我尝试过:
What I have tried:
cout << "Do you want to callculate the grade ? : ";
cin >> gradestocalculater;
for (int i = 0; i < gradestocalculater.length();i++){
gradestocalculater[i] = toupper(gradestocalculater[i]); //WORKING COMMAND
}
while(gradestocalculater == "YES")
{
cout << "Enter student type " << "(1-English, 2-Math,3-Sience): "; // COMAND EXECUTED
cin.getline(response,256); //COMAND DONT WORKING ???
if (strlen(response) == 0){
cout << "Please enter valid number...";
return 1;}
推荐答案
cout << "Response: " << response;
读取响应,但长度大于零,之后您正在处理代码,但不是您想要的。
使用看看发生了什么。
这篇关于有项目问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!