为什么我的数组不存储任何输入值?
Why doesn't my array store any input values?
我想按numCase
的次数将任意数字输入到数组b[]
中。
#include <iostream>
using namespace std;
//entry point
int main()
{
//Declarations
int b[20]; // array size 20 ( limit of inputs)
int c = 0;
int numCase;
int input;
cout << "ENTER NUMBER OF CASES (MAXIMUM NUMBER OF 20): n";
cin >> numCase;
//checks that numCase is less than or equal to (20) and does not exceed
if (numCase < 21)
{
// gets input number based on the numCase
do
{
cout << "ENTER A NUMBER (MAXIMUM OF 5 DIGITS): n";
cin >> input;
cout << "n";
b[c] = input;
c++;
} while (c != numCase);
cout << b[c] ; // this is my problem it OUTPUTS RANDOM VALUE,
//but i can see on my watch list that b has the values of my input.
}
}
您正在填写b
的0
至N
条目,然后打印未填写的N+1
条目
变量c
应该初始化为零。
} while (c != numCase);
c = 0;
count
我想这就是你要找的:
for (int i=0; i<numCase; i++)
{
if(b[i] >= x) //x is a variable that u can set as a limit. eg. 700
{
cout<<"n"<<b[i];
}
}
希望有所帮助
如果你想显示数组b中存储的所有数字[]然后你可以把你的代码写成
for(int i=0;i<=20;i++)
{ if(b[i]<101) //This will exclude all the values which are greater than 101
{cout<<"n"<<b[i];}}
相关文章:
- 打印时有二叉树问题.用户输入不打印任何内容
- 当可输入框在窗口中处于活动状态时获得通知的任何方法
- 在这个无限循环中,当输入 0 时终止,当输入 int 范围之外的任何内容时,程序行为不正常
- 如果用户没有输入任何内容或输入错误,如何重新输入用户的输入?
- 我觉得我放入结构中的输入代码可以压缩,关于如何在保持代码简短的同时保持数据个性化的任何建议?
- 如果我想使用 cout 为我的函数提供任何输入......我该如何给出
- 从输入中删除重复项,而不使用任何数据结构
- 有没有办法在函数 c++ 中输入任何数据类型?
- 是否有任何内置的哈希图函数来处理 c++ 中的值输入?
- 是否可以用类似C/C++(或任何语言)的语言,从作为用户输入的字符串或文件中创建用户定义的数据类型
- 是否可以编写C++不使用任何条件语句交换输入的函数?
- 为什么即使输入相等,v3 也不会返回任何内容
- 当我输入任何内容时,我的代码输出无效
- 我可以/应该在 #ifndef 后输入任何我想要的东西
- 为什么此代码只能识别文本文件中的第一行?输入任何大于 1 的数字都会返回"Atomic Number Not Found"
- 当没有输入任何输入时,C++getline不为空
- 如何检查用户是否没有输入任何字符串
- 在运行时间内用户输入任何内容时,如何停止计时器
- 为什么程序在 while 循环中继续输入任何字符
- 如果cin中没有输入任何内容,如何停止递归