我正在尝试让一个程序根据用户输入的数字打印出一个星号,例如 10-20 = 1 之间的数字等。我的问题是我不知道如何让打印功能发挥作用目前它没有打印任何东西。任何人都可以帮忙。
代码:
void readExamMarks(int examMarks[], int sizeOfArray, int counter1, int counter2){
cout << "Please enter a set of exam marks to see a histogram for:" << endl;
int x = 0;
for( int idx = 0; idx < sizeOfArray; idx++){
cin >> x;
if((x >=0) && (x <= 100)){
x = x/10;
switch(x){
case 1:
counter1++;
break;
case 2:
counter2++;
break;
}
examMarks[idx] = x;
}
else{
cout << "ERROR: Value must be in range [0...100], please enter a valid value\n";
}
}
}
void printExamMarks(int examMarks[], int sizeOfArray){
for(int x = 0; x < sizeOfArray; x++){
cout << setw(5) << examMarks[x];
}
cout << endl;
}
void printHisto(int examMarks[], int sizeOfArray,int counter1, int counter2){
system("cls");
while(counter1 != 0){
cout << "*" << endl;
counter1--;
}
for( int x = 0; x < counter1; x++){
cout << setw(5) << "*" << endl;
}
}
int main()
{
int examMarks[20];
int counter1 = 0;
int counter2 = 0;
readExamMarks(examMarks, 5, counter1, counter2);
printHisto(examMarks, 5, counter1, counter2);
printExamMarks(examMarks,5);
system("PAUSE");
}