我正试图解决这个问题,在输入之后,我没有在屏幕上得到任何输出。
给定以英寸为单位表示测量值的整数数组,编写计算总测量值的程序。
在脚里。忽略小于一英尺的测量值(例如,10英尺)
示例
从5个数字列表中找出以英尺为单位的总测量值
投入:-
投入1:
5
投入2:
18 11 27 12 14
产出:-
5
解释
第一个参数(5)是数组的大小,其次是以英寸为单位的测量数组。牙齿总数为5颗,计算如下:
18 -> 1
11-> 0
27 -> 2
12 -> 1
14-> 1
#include <iostream>
using namespace std;
int total = 0;
int main()
{
int arr[1000];
//int arr1[1000];
int size;
cin >> size;
int x;
for (int i = 0; i <= size; i++)
{
cin >> arr[i];
x = arr[i] / 12;
total = x + total;
x = 0;
}
cout << total;
return 0;
}
发布于 2020-11-25 10:20:24
您接受输入的次数比大小多一次。同时,x=0也是多余的。
#include <iostream>
using namespace std;
int total = 0;
int main()
{
int arr[1000];
//int arr1[1000];
int size;
cin >> size;
int x;
for (int i = 0; i < size; i++)
{
cin >> arr[i];
x = arr[i] / 12;
total = x + total;
//x = 0; Not required
}
cout << total;
return 0;
}
https://stackoverflow.com/questions/65001660
复制相似问题