错误信息:
这是什么意思?
我该如何解决?
错误C2040:'==':'int'的间接级别与'const char [2]'不同
码:
#include <iostream>
#include <cmath>
using namespace std;
int round(double number);
//Assumes number >=0.
//Returns number rounded to the nearest integer.
int main()
{
double doubleValue;
char ans;
do
{
cout << "Enter a double value: ";
cin >> doubleValue;
cout << "Rounded that number is " <<round(doubleValue)<< endl;
cout << "Again? (y/n): ";
cin >> ans;
}
//Here is the line generating the problem, while(...);
while (ans == 'y' || ans == "Y"); …Run Code Online (Sandbox Code Playgroud) #include <iostream>
using namespace std;
/*Use void functions, they perform some action but do not return a value*/
//Function Protoype, input,read in feet and inches:
void input (double& feet, double& inches);
//Function Prototype, calculate, calculate with given formulae.
void calculate(double& feet, double& inches);
//Function Prototype, output, outputs calculations to screen.
void output (double meters, double centimeters);
int main ()
{
double feet;
double inches;
char repeat;
do
{
//Call input:
input(feet, inches);
//Call calculate:
calculate(feet, inches);
//Call output:
output (feet, …Run Code Online (Sandbox Code Playgroud) 为什么我的C++数字不是随机的?
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int randomNumber = rand() % 100;
for (randomNumber = 0; randomNumber < 20; randomNumber++)
{
cout << randomNumber << endl;
}
return 0;
}
//Why are my 20 numbers not random?
Run Code Online (Sandbox Code Playgroud)