📄 hour05_1.cpp
字号:
// Listing 5.5 - demonstrates multiple return
// statements
#include <iostream>
int Doubler(int AmountToDouble);
int main()
{
int result = 0;
int input;
std::cout << "Enter a number between 0 and "
<< "10,000 to double: ";
std::cin >> input;
std::cout << "\nBefore doubler is called...";
std::cout << "\ninput: " << input
<< " doubled: " << result << "\n";
result = Doubler(input);
std::cout << "\nBack from Doubler...";
std::cout << "\ninput: " << input
<< " doubled: " << result << "\n\n";
return 0;
}
int Doubler(int original)
{
if (original <= 10000)
return original * 2;
else
return -1;
std::cout << "You can't get here!\n";
// The line above should never execute and you may get a warning
// about unreachable code. Comment it out and recompile, what's the message now?
// You may also get a warning about not having a return at the end of the function
// even know *we* know the the code is unreachable, the compiler may not detect that.
// Uncomment the following line and see what happens when you compile.
// return 0;
// Sometimes error and warning messages can be a little confusing!
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -