我通过翻阅我的C++书并重新编写C中的问题来教自己C.我想知道在C中声明变量常量的正确的行业标准方法.你还在main之外使用#define指令,还是可以使用main中的C++样式const int?
尝试编译一个包含5个选项的简单switch语句.1-4产生计算和输出,而#5退出程序.我做了一个do/while循环,所以如果输入选项5,程序将结束.我收到一个错误:
4_19.c: In function ‘main’:
4_19.c:95: error: ‘choice’ undeclared (first use in this function)
4_19.c:95: error: (Each undeclared identifier is reported only once
4_19.c:95: error: for each function it appears in.)
Run Code Online (Sandbox Code Playgroud)
我不知道为什么它说它未宣布,因为我在开始时宣布它.我做错了什么?感谢名单.这是我的代码:
/* C++ book. 4_19 The speed of sound in gases.
Create a menu to choose between 4 gases. User then enters number of seconds
it took to travel to destination. The program will calculate how far the source was (from speed that is unique to gas density). Validate …Run Code Online (Sandbox Code Playgroud) 我是一名计算机科学专业的学生并参加了我的第一个C++课程.我有一个问题,了解我的代码发生了什么:
// This program uses the address of each element in the array.
#include <iostream>
using namespace std;
int main()
{
const int NUM_COINS = 5;
int coins[NUM_COINS] = {5, 1, 25, 5, 10};
int *p1; // Pointer to a double.
int count; // Counter variable.
// Use the pointer to display the values in the array.
cout << "Here are the values in the coins array: \n";
for(count = 0; count << NUM_COINS; count++)
{
// Get the address …Run Code Online (Sandbox Code Playgroud) 我正在学习C++,需要帮助我的代码.我不明白我的第二个函数中是如何得到编译器错误的.它几乎是第一个镜像,但我没有从第一个得到任何错误.
#include <iostream>
using namespace std;
// Function prototypes
int getLargest(int[], int);
int getSmallest(int[],int);
int main()
{
const int ARRAY_SIZE = 10;
int array[ARRAY_SIZE];
int count = 0;
cout << "Please enter 10 numbers into the array.\n\n";
for (count; count < ARRAY_SIZE; count++)
{
cout << "Number " << (count +1) << ": " ;
cin >> array[count];
}
// Call function to calculate largest number.
int largest = getLargest(array, ARRAY_SIZE);
// Display the largest number
cout << "The largest …Run Code Online (Sandbox Code Playgroud)