本文介绍了如何编写一个不包含21的数字的f语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include <iostream>
using namespace std;
int main() {
const int NUM_ELEMENTS = 8; // Number of elements
int userVals[NUM_ELEMENTS]; // User numbers
int i = 0; // Loop index
// Prompt user to populate array
cout << "Enter " << NUM_ELEMENTS << " integer values..." << endl;
for (i = 0; i <= NUM_ELEMENTS; ++i) {
cout << "Value: " << endl;
cin >> userVals[i];
}
// Determine values greater than 21
for (i = 0; i <= NUM_ELEMENTS; ++i) {
if //This is where I am stuck.....
cout << endl << userVals[i] << endl;
}
return 0;
}
推荐答案
int a = 1;
if (a > 0)
// or
int a = 1
int b = 2
if (a > b)
结论...
in conclusion...
for (i = 0; i <= NUM_ELEMENTS; ++i) {
if (userVals[i] > 21) // or if (userVals[i] >= 22)
cout << endl << userVals[i] << endl;
}
这篇关于如何编写一个不包含21的数字的f语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!