本文介绍了为什么即使没有随机数,此代码也会返回一个随机数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我没有包含任何随机函数,它仍然在程序结束时返回一个随机数。请帮忙。这是一个可以进行基本数学运算的数学计算器。 #include #include #include #include #include #include #include #include #include #include 使用 命名空间标准; string play_again; void wait( double 秒) { clock_t endwait; endwait = clock()+ seconds * CLOCKS_PER_SEC; while (clock()> x; cout> y; cout> x; cout > y; cout> x; cout> y; cout> x; cout> y; cout> ans; if (ans == ' M'){ 乘(num1,num2); } 其他 if (ans == ' D'){ 除(num1,num2); } else if (ans == ' S'){ 减法(num1,num2); } else if (ans == ' A'){ add(num1,num2); } 其他 { cout>再玩一次; if (play_again == Y ){ askMathFunction(); } else if (play_again == N){ cout<< load( 退出); return 0 ; } 其他 { cout<< 请输入内容......<< ENDL; playagain(); } } int main(){ load( 正在加载); cout<< 计算器开始......<<的std :: ENDL; cout<< 按ENTER开始<<的std :: ENDL; cin.ignore(); askMathFunction(); playagain(); while (play_again == Y ){ playagain(); } return 0 ; } 我的尝试: 1.我试过重写程序。 2.我试图改变所有的值。解决方案 该代码将无法编译:您多次调用的函数 playagain 不存在,也不是 askMathFunction 如果您的代码编译不干净,那么它就不会生成EXE文件,也无法执行它。 所以你测试的代码版本与你正在看的代码不一样,它产生的任何结果都是毫无价值的! 你有很多 #include 不执行任何操作的语句。你有很多 cout> y (和其他变量名称),也什么都不做。我建议你回到你的文档并阅读 cin 方法,将参数传递给函数,包括头文件等等。 I did not include any random functions and it still returns a random number at the end of the program. Please help. This is a math calculator that can do basic math operations. #include #include #include #include #include #include #include #include #include #include using namespace std; string play_again; void wait ( double seconds ) { clock_t endwait; endwait = clock () + seconds * CLOCKS_PER_SEC ; while (clock() > x; cout > y; cout > x; cout > y; cout > x; cout > y; cout > x; cout > y; cout > ans; if(ans == 'M') { multiply(num1, num2); } else if(ans == 'D') { divide(num1, num2); } else if(ans == 'S') { subtract(num1, num2); } else if(ans == 'A') { add(num1, num2); } else { cout > play_again; if (play_again == "Y") { askMathFunction(); } else if (play_again == "N") { cout<< load("Logging out"); return 0; } else { cout<< "Please enter something..."<< endl; playagain(); } } int main( ){ load("Loading"); cout << "Calculator starting... " << std::endl; cout << "Press ENTER to start" << std::endl; cin.ignore(); askMathFunction(); playagain(); while(play_again == "Y") { playagain(); } return 0; }What I have tried:1. I have tried re-writing the program.2. I have tried to change all the values. 解决方案 That code won't compile: the function you call several times playagain isn't there, nor is askMathFunctionIf your code doesn't compile cleanly, then it doesn't produce an EXE file, and you can't execute it.So the version of code you are testing is not the same as the code you are looking at, and any results it produces are pretty much worthless!You have lots of #include statements that do nothing. You have lots of cout > y (and other variable names), that also do nothing. I suggest you go back to your documentation and read up on the cin method, passing parameters to functions, including header files, etc., etc. 这篇关于为什么即使没有随机数,此代码也会返回一个随机数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-13 16:03