小编USD*_*des的帖子

将小数舍入为整数

我环顾四周,找不到我想要的东西.

我想将我的所有数字四舍五入到整数.

例如:
5.9将是6
5.5将是6
5.1将是6
5.000001122将是6
5.0将是5

我在考虑是否将它们放入可以摆脱小数的整数但由于小数点刚刚下降而看起来不正确.我在这里纠正吗?

所以我想到这样做,然后在最终结果中加1,这将解决大约99%的问题,但如果我的结果为5,我不想添加1.

我将如何解决这个问题呢?

c++

2
推荐指数
2
解决办法
2147
查看次数

如何改进我的C++代码?

这是我在hello world之外创建的第一个程序.代码超过400行代码,想要了解新功能,这有助于改善我的代码和我对C++的了解.我想我会潜入并自己学习而不是出自"我每天一小时第六版自学C++"的书.

我可以学到哪些新功能可以改善我的代码?

// Runescape Mining Calculator

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    int lvl;
    int exp;
    int result;

    cout << " \t\t\tRunescape Skill Calculator" << endl;
    cout << " Enter Target level: ";
    cin>>lvl;

    switch(lvl)
    {
                    case 2: cout << " What is your current experience? ";;
                    cin >> exp;
                    result=83 - exp;
                    break;
                    case 3: cout << " What is your current experience? ";
                    cin >> exp;
                    result=174 - exp;
                    break;
                    case 4: cout …
Run Code Online (Sandbox Code Playgroud)

c++

2
推荐指数
1
解决办法
386
查看次数

C++ Guess Number游戏在其他计算机上崩溃并且无限循环修复

// Guess my number
// My first text based game
// Created by USDlades
// http://www.USDgamedev.zxq.net

#include <cstdlib>
#include <ctime>
#include <string>
#include <iostream>

using namespace std;


int main()
{

    srand(static_cast<unsigned int>(time(0))); // seed the random number generator

    int guess;
    int secret = rand() % 100 + 1; // Generates a Random number between 1 and 100
    int tries =0;

    cout << "I am thinking of a number between 1 and 100, Can you figure it out?\n";

    do 
    {
        cout …
Run Code Online (Sandbox Code Playgroud)

c++

1
推荐指数
1
解决办法
861
查看次数

标签 统计

c++ ×3