Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 添加错误、简单问题_C++_Visual C++ - Fatal编程技术网

C++ 添加错误、简单问题

C++ 添加错误、简单问题,c++,visual-c++,C++,Visual C++,菜鸟问题!当我运行这个,我把客人的数量设为2,我应该有2个小比萨饼,因为这个数字不大于3(使之成为中等),当我运行它时,它告诉我所有尺寸的0。舍入误差?我该如何解决这个问题--请说英语,我是初学者:) #包括 #包括 #包括 使用名称空间std; int main() { //提示用户 cout>与会者; int large_pizzas=与会者/7; cout也许你可以调整你想要的方式: #include <iostream> #define LARGE_PIZZA_SHARE

菜鸟问题!当我运行这个,我把客人的数量设为2,我应该有2个小比萨饼,因为这个数字不大于3(使之成为中等),当我运行它时,它告诉我所有尺寸的0。舍入误差?我该如何解决这个问题--请说英语,我是初学者:)

#包括
#包括
#包括
使用名称空间std;
int main()
{
//提示用户
cout>与会者;
int large_pizzas=与会者/7;

cout也许你可以调整你想要的方式:

#include <iostream>

#define LARGE_PIZZA_SHARE 7     // 7 persons can share 1 large pizza
#define MEDIUM_PIZZA_SHARE 3    // 3 persons can share 1 medium pizza
#define SMALL_PIZZA_SHARE 1     // 1 person - 1 small pizza

int main()
{
    int attendees = 0;
    cout << "Enter number of attendees: ";
    cin >> attendees;

    int largePizzaCount = 0;
    int mediumPizzaCount = 0;
    int smallPizzaCount = 0;

    if (attendees >= LARGE_PIZZA_SHARE)
    {
        largePizzaCount = attendees / LARGE_PIZZA_SHARE;
        attendees = attendees % LARGE_PIZZA_SHARE; 
    }

    if (attendees >= MEDIUM_PIZZA_SHARE)
    {
        mediumPizzaCount = attendees / MEDIUM_PIZZA_SHARE;
        attendees = attendees % MEDIUM_PIZZA_SHARE;
    }

    if (attendees >= SMALL_PIZZA_SHARE)
    {
        smallPizzaCount = attendees / SMALL_PIZZA_SHARE;
    }

    cout << "You require: " << largePizzaCount << " large pizzas, " << mediumPizzaCount << " medium pizzas, and " << smallPizzaCount << " small pizzas!" << endl;

    return 0;
}
#包括
#定义大比萨饼共享7//7人可以共享1个大比萨饼
#定义中号比萨\u共享3//3人可以共享1个中号比萨
#定义小比萨饼分享1//1人-1个小比萨饼
int main()
{
int与会者=0;
cout>与会者;
int largepizzaccount=0;
int mediumPizzaCount=0;
int smallpizzaccount=0;
如果(与会者>=大比萨饼分享)
{
LargePizzaccount=与会者/大比萨份额;
与会者=与会者%LARGE\u PIZZA\u份额;
}
如果(与会者>=中等比例)
{
Mediumpizzaccount=与会者/中等比萨饼份额;
与会者=与会者%中等份额;
}
如果(与会者>=小型比萨饼分享)
{
Smallpizzaccount=与会者/小比萨饼份额;
}

不能在调试器中单步执行。想想
%1
的意思。你太棒了!
#include <iostream>

#define LARGE_PIZZA_SHARE 7     // 7 persons can share 1 large pizza
#define MEDIUM_PIZZA_SHARE 3    // 3 persons can share 1 medium pizza
#define SMALL_PIZZA_SHARE 1     // 1 person - 1 small pizza

int main()
{
    int attendees = 0;
    cout << "Enter number of attendees: ";
    cin >> attendees;

    int largePizzaCount = 0;
    int mediumPizzaCount = 0;
    int smallPizzaCount = 0;

    if (attendees >= LARGE_PIZZA_SHARE)
    {
        largePizzaCount = attendees / LARGE_PIZZA_SHARE;
        attendees = attendees % LARGE_PIZZA_SHARE; 
    }

    if (attendees >= MEDIUM_PIZZA_SHARE)
    {
        mediumPizzaCount = attendees / MEDIUM_PIZZA_SHARE;
        attendees = attendees % MEDIUM_PIZZA_SHARE;
    }

    if (attendees >= SMALL_PIZZA_SHARE)
    {
        smallPizzaCount = attendees / SMALL_PIZZA_SHARE;
    }

    cout << "You require: " << largePizzaCount << " large pizzas, " << mediumPizzaCount << " medium pizzas, and " << smallPizzaCount << " small pizzas!" << endl;

    return 0;
}