gpt4 book ai didi

c++ - 函数未在此范围内声明?

转载 作者:行者123 更新时间:2023-11-27 23:48:34 32 4
gpt4 key购买 nike

<分区>

我正在尝试编写一个根据输入显示星号和空格的程序,但我遇到了一个编译器问题:

chart.cpp:24:41: error: ‘find_largest’ was not declared in this scope
int largest = find_largest(values, size);

这是我的代码:

/*
* Project 1
* Author: Erik Ingvoldsen
* Date: 2/1/2018
*/

#include <iostream>
using namespace std;

int size = 0; //initalizing "size" at 0.
const int MAX = 100; //setting max value
int values[MAX]; //100 int limit

int main(){
int num;
for (int i = 0; i < MAX; i++) {
cin >> num; //allow the user to put in a number
values[i] = num; //assigning value to the array
if (num <= 0) {
break; //stop if "0" or lower is entered
}
size++; //increase the size of array, assuming the for loop hasn't been broken
}
int largest = find_largest(values, size); //setting the amount of rows
for (int i = 0; i < size; i++) {
if (values[i] = largest) {
cout << "*"; //if the value of the area reachest the highest row, give a *
} else {
cout << "\n"; //otherwise just give a blank space
}
largest--; //by shrinking "largest", we move down the next row
cout << endl;
}
return 0;
}

int find_largest(int values[], int size) {
int largest = 0;
for (int i = 0; i < size; i++) {
if (values[i] > largest) {
largest = values[i]; //if the value of the array is bigger than the current largest it is replace
}
}
return largest; //once the for loop is completed, it returns the largest number found
}

我真的分不清这个函数和函数之间的区别...而且我很确定我不应该将它声明为“int largest = find_largest(values[], size);”

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com