always returning 466750944 in c++ calculations script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | #include <iostream> using namespace std; multiplication() { int x; int y; int sum; sum = y * x; cout <<"multiplication" << endl; cout <<"enter first number for multiplication:"; cin >> x; cout <<"enter second number for multiplication:"; cin >> y; cout <<"your product is:" << sum <<endl; return 0; } void division (){ cout <<"division" << endl; } void addition (){ int y; int x; int sum = x * y; cin >> x; cin >> y; cout << sum; } void subtraction (){ } int main() {cout <<"enter 1 for multiplication, enter 2 for division, enter 3 for addition, and enter 4 for subtraction"<<endl; int math; cin >> math; switch(math){ case 1: multiplication(); break; case 2: division(); default: cout <<"it dont work ooga booga"<<endl; break; case 3: addition (); break; case 4: subtraction();} return 0; } |
这是我正在尝试运行的脚本,我在code::blocks中运行。如果有什么错误会导致它始终返回466750944,请告诉我,以便我可以在这方面做更多的工作。这可能是我在codeblocks中的一个问题,如果有人也可以在codeblocks或另一个IDE中运行此脚本并发布其结果,这将是非常感谢的,thaNK优
当你说在定义点计算的
执行
要了解这种行为的实际情况,请在调试器中单步执行代码,并查看
要么把它移到正确定义了
1 2 3 | int sum(int x, int y) { return x * y; } |