在单独的数据中显示数组数据
Display array data in seperate data
我是一名学生,目前要学习一个非常基础的计算机编程模块。问题是,他们并不完全教授C++编程语言,而是教授其中的一些内容,并期望我们能够自己拼凑拼图并构建一个程序来磨练我们的"问题思维技能"。
我希望在数组中显示数据,隐藏在单独的项目中。换句话说,数据在一个数组中,在一个称为 data
的单独项目中,而在主程序中,我想在用户选择时显示数据。
例如,在每月天气数据的上下文中,我怎样才能使信息排列成数组,以显示用户何时输入某一天。因此,当用户在 21
中键入时,它应该显示该月21日的温度,也显示在数组的第20个索引处。
这是我到目前为止所做的:
printf("Enter selected month.n");
scanf_s("%c", &month);
if (month==October)
{
printf("Enter selected date, from 1st to 31st.n");
scanf_s("%d", &octoberTemperature[i]);
printf("%.2fn", octoberTemperature[i]);
}
非常欢迎任何帮助! :)
&octoberTemperature[i]
你遇到了一个问题 - 你正在尝试写入数组的对象。你应该这样做:
printf("Enter selected month.n");
scanf_s("%c", &month);
unsigned short day = 0;
if (month==October)
{
printf("Enter selected date, from 1st to 31st.n");
scanf_s("%d", &day);
printf("%.2fn", octoberTemperature[day - 1]);
// as it starts from 0
// if your array containing the month report starts from 0 then it has to be (day - 1)
}
在您的代码中,您实际上已经输入了您希望在数组中查找天气的日期并打印了相同的数组。现在不要使用相同的 var 来获取日期作为输入
scanf ("%d",&day)//I assumed day as a var to receive the month day
cout<<Octobertemperature[day-1];
// now if u already have a array containing the data of the weather report..then this will solve your problem.
相关文章:
- 从数据库实时显示QT c++中的数据
- 当使用比格式支持的精度更高的精度来显示数字时,会写出什么数据
- C++射线示踪剂ppm表示没有足够的数据来显示图像
- QChart在使用QDateTimeAxis时不显示任何系列数据
- 如何存储用户输入的所有数据,然后在他们想要查看所有数据时显示它们
- 访问和打印元组中的数据,并使用 C++14 使用模板函数显示数据
- 运算符重载以显示用户定义的数据类型
- 如何在不使用委托的 QML 中显示模型数据
- 从文本文件中读取并输入到数组结构中,然后显示读取的数据C++
- 如何从amd gpus的显示输出中获取图像数据
- 它不显示数据,只显示永无止境的循环
- C++ 矢量不显示包含对象的数据
- 如何在数据文件中查找和显示内容
- Qt - 将空指针(原始数据)转换为 QImage 并将其显示在标签上
- 在QT C++编辑Qtable模型数据时,我需要得到一个小盒子,我需要显示编辑文本,这怎么可能?
- 通过显示一行星号来创建条形图,该条形图将读取数据的输入文件
- 如果构造函数和析构函数可以获取和显示(打印)数据,为什么我们需要 getter 和 setter?
- 在网格视图中显示数据 - 基于 MFC c++ 对话框的应用程序
- 使 XML 数据显示在 Blackberry 10 Cascades QML 中的 listItemComponents
- 提示用户键入 0 到 99 之间的 20 个整数.从该数据显示质数