如何显示用户花费的号码,即用户输入了多少时间
how to show the number taken by user that how much time it is entered by user
>好的,该程序在使用循环时似乎很容易,但是如果还有其他条件可以做到这一点呢我已经尝试过,这是我的努力,但完全失败了。
#include<iostream>
#include<conio.h>
int main(){
using namespace std;
int a,b,c,d,e,f,g,h,j,k,l;
int c1=0;
int c2=0;
int c3=0;
int c4=0;
cout<<"please enter first numbern";
cin>>a;
cout<<"please enter second numbern";
cin>>b;
cout<<"please enter third numbern";
cin>>c;
cout<<"please enter fourth numbern";
cin>>d;
cout<<"please enter fifth numbern";
cin>>e;
cout<<"please enter sixth numbern";
cin>>f;
cout<<"please enter seventh numbern";
cin>>g;
cout<<"please enter eighth numbern";
cin>>h;
cout<<"please enter ninth numbern";
cin>>j;
cout<<"please enter tenth numbern";
cin>>k;
cout<<"please enter eleventh numbern";
cin>>l;
if(a==1)
{
c1=a+1;
}
else if (a==1 && b==1)
{
c2=a+b;
}
else if (a==1 && b==1 && c==1)
{
c3=a+b+c;
}
else if (a==4)
{
c4=a+1;
}
cout<<"no of 1's="<<c1;
getch();
}
我正在取值,取值后我想显示 1 出现多少时间
使用循环输入N
数字。当你阅读它们时(当然要确保检查错误(,计算你得到数字 1 的次数。
要计算字母变量中有多少个ones
,您可以这样做:
int c1=0;
if(a==1)
{
c1++;
}
if (b==1)
{
c1++;
}
...
if (l==1)
{
c1++;
}
cout<<"no of 1's="<<c1;
#include<iostream>
#include<conio.h>
#include <array>
#include <unordered_map>
int main(){
using namespace std;
static const int cCount = 11;
array<int, cCount> values;
static const array<std::string, cCount> numbers = {
"first",
"second",
。
"eleventh"};
for (int = 0; i < cCount; ++i) {
cout<<"please enter " << numbers[i] << " numbern";
cin>> values[i];
}
unordered_map<int, int> counts;
for (int = 0; i < cCount; ++i) {
++counts[values[i]];
}
cout << "no of 1's=" << counts[1];
getch();
}
哇,真是一团糟。
使用哈希表,键是用户输入,值是无符号的(此无符号将跟踪用户使用相应键输入值的次数(。每当用户输入值时,请递增该键处的值。然后,在最后,返回存储在键 == '1' 的值。
相关文章:
- C++如何通过用户输入删除列表元素
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 如何使用用户输入在C++中正确填充2D数组
- C++MySQL C api用户输入行
- 使用用户定义函数的字符串反转
- 用户定义函数中的指针和输入
- 为什么即使使用-cudart-static进行编译,库用户仍然需要链接到cuda运行时
- 如何只允许用户输入正整数
- C++如何计算用户输入的数字中的偶数位数
- 通过for循环使用用户输入填充列表
- 这是我尝试让用户将值输入到数组中.然后将其隐藏为大量的星号
- 在C++中,我如何接受不同于同一行的用户输入
- 当用户超过按钮点击限制时报告
- Visual C++(VS2017)中用户定义的转换不明确
- 如果用户输入无效,如何使用字符串变量-C++重复输入命令
- 如何让程序只运行用户输入的号码?
- 使用 Firebase 从C++获取用户的电话号码
- 如何让计算机在 7 个问题中正确猜测用户的号码
- C++:如果用户输入的号码有误,则要求用户输入新号码
- 如何显示用户花费的号码,即用户输入了多少时间