该代码不会在其中显示任何数字输入.如何使它显示任何输入
the code will not display any number input into it. how to make it so it will display whatever is the input?
>我正在使用天,小时和分钟在c ++中做一个3d数组,用户可以输入任何数字,它将显示为day:hour:minute问题是代码不会显示任何给定的数字。
我尝试将 for 循环中的天、小时和分钟设置为 1 并且有效,但仅当输入 1 时,任何其他数字都不会运行
int main()
{
float temp[365][24][23] = { 0.0 };// this sets the array to have no more then 365 days-change temp to days
char stop = 'n';
int hour = 1;
int min = 1;
int dayz = 1; // will change i to temp
do
{
std::cout << "please give me a day from 1-365" << std::endl;//tells users that 1-365 days are needed
std::cin >> dayz;
std::cout << "plese give me a number from 1-24 hours " << std::endl;//tells users that 1-365 days are neede
std::cin >> hour;
std::cout << "please give me the minute" << std::endl;//tells users that 1-365 days are needed
std::cin >> min;
std::cout << "enter the temperature for today" << " = "; //prompt users to keep on giving temperatures
std::cin >> temp[dayz][hour][min];
std::cout << "If you want to end the program type N.If you dont then type any number" << std::endl; // tells users after date and temperatures are entered if the they want to stop type 0 and if not press anynumber
std::cin >> stop;
} while (stop != 'N' && stop != 'n');
for (dayz = 0; dayz <=364; ++dayz)// makes the calendar and keeps it less then 366 issue is that it will show the same date multiple time
{
for (hour = 0; hour <=23; ++hour)// keeps the calendar orderly
{
for (min = 0; min <= 22; ++min)
{
if (temp[dayz][hour][min] != 0.0)
{
std::cout << dayz << ":" << hour << ":" << min << " = " << temp[dayz][hour][min] << "/t "; //will display all the input
}
}
return 0;
}
}
}
你在内部循环之后写return 0;
,我想这不是你想要的。你应该使用std::string stop = "n";
并比较stop != "N" && stop != "n"
试试这个。
int main(){
float temp[365][24][23] = { 0.0 };// this sets the array to have no more then 365 days-change temp to days
char stop = 'n';
int hour = 1;
int min = 1;
int dayz = 1; // will change i to temp
do{
std::cout << "please give me a day from 1-365" << std::endl;//tells users that 1-365 days are needed
std::cin >> dayz;
std::cout << "plese give me a number from 1-24 hours " << std::endl;//tells users that 1-365 days are neede
std::cin >> hour;
std::cout << "please give me the minute" << std::endl;//tells users that 1-365 days are needed
std::cin >> min;
std::cout << "enter the temperature for today" << " = "; //prompt users to keep on giving temperatures
std::cin >> temp[dayz][hour][min];
std::cout << "If you want to end the program type N.If you dont then type any number" << std::endl; // tells users after date and temperatures are entered if the they want to stop type 0 and if not press anynumber
std::cin >> stop;
} while (stop != 'N' && stop != 'n');
for (dayz = 0; dayz <=364; ++dayz)// makes the calendar and keeps it less then 366 issue is that it will show the same date multiple time
{
for (hour = 0; hour <=23; ++hour)// keeps the calendar orderly
{
for (min = 0; min <= 22; ++min){
if (temp[dayz][hour][min] != 0.0)
std::cout << dayz << ":" << hour << ":" << min << " = " << temp[dayz][hour][min] << "/t "; //will display all the input
}
}
}
return 0;
}
所以,我找到了一种方法来修复它,只需摆脱 for 循环并将 min 的 for 循环转换为 if 语句
。 例如。int main()
{
float temp[364][23][59] = { 0.0 };//-1073741571 i get this error when i put minute in 59
char stop = 'n';
int hour = 1;
int min = 1;
int dayz = 1; // when i dont get the error code the program doesnt show
do
{
std::cout << "please give me a day from 1-365" << std::endl;//tells users that 1-365 days are needed
std::cin >> dayz;
std::cout << "plese give me a number from 1-24 hours " << std::endl;//tells users that 1-365 days are neede
std::cin >> hour;
std::cout << "please give me the minute" << std::endl;//tells users that 1-365 days are needed
std::cin >> min;
std::cout << "enter the temperature for today" << " = "; //prompt users to keep on giving temperatures
std::cin >> temp[dayz][hour][min];
std::cout << "If you want to end the program type N.If you dont then type any number" << std::endl; // tells users after date and temperatures are entered if the they want to stop type 0 and if not press anynumber
std::cin >> stop;
} while (stop != 'N' && stop != 'n');
if (min < 61 )
{
std::cout << dayz << ":" << hour << ":" << min << " = " << temp[dayz][hour][min] << "/t "; //will display all the input
return 0;
}
}
相关文章:
- QChart在使用QDateTimeAxis时不显示任何系列数据
- 为什么静态数组成员变量在调用对象的实例后不显示任何内容?
- 为什么下面的Hello World程序在PowerShell上没有显示任何输出?同一程序在CMD上显示正确的输出
- Gtkmm 窗口为空白,不显示任何小部件或标题
- 执行此代码时,它不显示任何输出.为什么?
- 编译器没有显示错误,但我没有得到任何输出.怎么了?
- 以编程方式在任何按钮上突出显示 Qt 鼠标悬停按钮
- C++ 矢量未显示我插入的任何值
- 螺旋矩阵在最后一个"for"循环中中断,不显示任何内容
- 为什么 C++ 中的分号在插入代码开头时不显示任何错误?
- 如何将计算机中的任何视频加载并显示到 UWP (C++)
- 在窗口中显示任何内容之前和窗口抛光后无法进行介绍
- c ++ 是否有任何用于列出 Windows 驱动程序管理器控制台中显示的设备驱动程序的 Windows API?
- 后缀Expressrion的插图未显示任何输出
- QGraphicView不显示任何内容
- 在任何 Windows 版本上全屏显示控制台
- 由于错误,c ++代码无法在Visual Studios上运行,但不显示任何错误
- 不显示任何输出
- OpenGL程序不显示任何图片
- Visual C++ 2013 程序在 IDE 中工作,但在 InstallShield LE 安装后不加载任何显示内容