#include <cstdio>
int main ()
{
unsigned long long int n;
scanf("%llu",&n);
printf("n: %llu\n",n);
n /= 3;
printf("n/3: %llu\n",n);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
无论我输入什么,我都会得到非常奇怪的输出,例如:
n: 1
n/3: 2863311531
Run Code Online (Sandbox Code Playgroud)
要么
n: 2
n/3: 2863311531
Run Code Online (Sandbox Code Playgroud)
要么
n: 1000
n/3: 2863311864
Run Code Online (Sandbox Code Playgroud)
什么原因?我该怎么做才能正确?
(g ++ 3.4.2,Win XP)
下面是我的代码的副本。基本上,我需要创建一个程序,根据“工资代码”(例如工人的职位)计算工资。我已经创建了我的 switch 语句,除了我输入第一个付款码时的一开始,一切正常。我输入第一个付款代码,它会转到下一行,将其留空。我输入另一个数字,它会按照预期的方式运行该数字和前一个数字。然后,一切正常。我确信这是一个简单的解决方案,但对我来说有点棘手。另外,我不确定应该如何在这里格式化我的代码,使其看起来像在服务器上一样,所以我对它看起来令人困惑的方式表示歉意。
#include <stdio.h> //precompiled header
int main(void)
{
//declare variables
unsigned int counter = 0; //counters to calculate amount of workers paid
unsigned int counter2 = 0;
unsigned int counter3 = 0;
unsigned int counter4 = 0;
int paycode;
float overtime; //amount of overtime hours
float salary; //weekly salary
float hoursWorked;
float hourlyRate;
float grossWeeklySales; //weekly sales for commissioned workers
int itemsProduced;
float fixedAmount; //money given per item produced
//prompt for input
printf("Please enter the employee's paycode.\n");
printf("1: …Run Code Online (Sandbox Code Playgroud)