#include
using namespace std;
int main()
{
const int number1, number2, product;
cout << "Enter two numbers and I will multiply\n";
cout << "them for you.\n";
cin >> number1 >> number2;
product = number1 * number2;
cout << product <
return 0;
}
我猜你是想这么用,代码,再说下const是什么意思啊,被const修饰的变量就会变成常量,比如const int a = 1;那么a的值就不能改了,改是会报错的,a就等于1了,所以上面你那么写会报错,懂了吧
#include<iostream>
using namespace std;
int main()
{
int number1, number2, product;
cout << "Enter two numbers and I will multiply\n";
cout << "them for you.\n";
cin >> number1 >> number2;
product = number1 * number2;
cout << product << endl;
return 0;
}
效果:
const 定义常量 可以理解为不可以变的变量
const是常量修饰符,用了它,那么这个变量就不能再修改值。很少用到const,一般用在全局变量,或者指针。因为要传参,为了防止参数被修改,就用常量修饰。