- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
下面是我的代码的副本。基本上,我需要创建一个基于“工资代码”(例如 worker 的职位)计算工资的程序。我已经创建了我的 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: Manager\n");
printf("2: Hourly Worker\n");
printf("3: Commission Worker\n");
printf("4: Pieceworker\n");
printf("-1 to end\n");
printf("%s","Paycode: ");
scanf("%d\n", &paycode);
while (paycode != -1)//begin while loop
{
switch(paycode)
{
case 1: //calculate manager's pay
printf("Manager selected.\n");
printf("Enter weekly salary: $ ");
scanf("%f", &salary);
counter = counter + 1;
printf("Weekly salary is %.2f\n\n", salary);
break;
case 2:
printf("Hourly worker selected.\n");
printf("Enter hourly rate: $");
scanf("%f", &hourlyRate);
printf("Enter hours worked: ");
scanf("%f", &hoursWorked);
if(hoursWorked<=40) //if statement to calculate overtime
{
salary=hourlyRate*hoursWorked;
printf("No overtime worked.");
}
else
{
salary=40.0*hourlyRate+(hoursWorked-40)*1.5*hourlyRate;
overtime = hoursWorked - 40;
printf("Total amount of overtime worked: %.2f\n", overtime);
}
counter2 = counter2 +1;
printf("Weekly salary is: $%.2f\n\n", salary);
break;
case 3:
printf("Commissioned worker selected.\n");
printf("Enter gross weekly sales: $");
scanf("%f", &grossWeeklySales);
salary=.057*grossWeeklySales+250;
counter3 = counter3 +1;
printf("Weekly salary is: $%.2f\n\n", salary);
break;
case 4:
printf("Pieceworker Selected.\n");
printf("Enter amount of items produced: ");
scanf("%d", &itemsProduced);
printf("Enter the fixed pay per item produced: $ ");
scanf("%f", &fixedAmount);
salary=itemsProduced*fixedAmount;
counter4 = counter4 + 1;
printf("Weekly salary is: $%.2f\n\n", salary);
}
//get next input
printf("Please enter paycode, -1 to end.\n");
printf("%s","Paycode: ");
scanf("%d", &paycode);
}
printf("Number of managers paid: %d\n", counter); //display amount of workers paid
printf("Number of hourly workers paid is: %d\n", counter2);
printf("Number of commisioned workers is: %d\n", counter3);
printf("Number of piece workers paid is: %d\n\n", counter4);
}
最佳答案
'\n'
scanf("%d\n", &paycode)
格式字符串中的字符匹配给定输入中任意数量的空白字符(空格、制表符、换行符等-isspace
中声明的ctype.h
函数产生真值的字符)。因此,scanf
call 将读取并丢弃任意数量的空白字符,直到遇到非空白字符,此时它将返回。对于 scanf
格式字符串中的任何空白字符都是如此。不仅是换行符。例如,以下将表现出相同的行为:
scanf("%d ", &paycode)
^ a space
scanf
拨电至
scanf("%d", &paycode);
printf("%s", "Paycode: ");
你可以简单地写
printf("Paycode: ");
您已评论
stdio.h
是一个预编译的头文件。它不是。它是一个包含宏定义和函数声明或原型(prototype)的头文件。它不是预编译意义上的目标文件。
关于c - 换行符在格式字符串中时 scanf 的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21859277/
如何使用 SPListCollection.Add(String, String, String, String, Int32, String, SPListTemplate.QuickLaunchO
我刚刚开始使用 C++ 并且对 C# 有一些经验,所以我有一些一般的编程经验。然而,似乎我马上就被击落了。我试过在谷歌上寻找,以免浪费任何人的时间,但没有结果。 int main(int argc,
这个问题已经有答案了: In Java 8 how do I transform a Map to another Map using a lambda? (8 个回答) Convert a Map>
我正在使用 node + typescript 和集成的 swagger 进行 API 调用。我 Swagger 提出以下要求 http://localhost:3033/employees/sear
我是 C++ 容器模板的新手。我收集了一些记录。每条记录都有一个唯一的名称,以及一个字段/值对列表。将按名称访问记录。字段/值对的顺序很重要。因此我设计如下: typedef string
我需要这两种方法,但j2me没有,我找到了一个replaceall();但这是 replaceall(string,string,string); 第二个方法是SringBuffer但在j2me中它没
If string is an alias of String in the .net framework为什么会发生这种情况,我应该如何解释它: type JustAString = string
我有两个列表(或字符串):一个大,另一个小。 我想检查较大的(A)是否包含小的(B)。 我的期望如下: 案例 1. B 是 A 的子集 A = [1,2,3] B = [1,2] contains(A
我有一个似乎无法解决的小问题。 这里...我有一个像这样创建的输入... var input = $(''); 如果我这样做......一切都很好 $(this).append(input); 如果我
我有以下代码片段 string[] lines = objects.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.No
这可能真的很简单,但我已经坚持了一段时间了。 我正在尝试输出一个字符串,然后输出一个带有两位小数的 double ,后跟另一个字符串,这是我的代码。 System.out.printf("成本:%.2
以下是 Cloud Firestore 列表查询中的示例之一 citiesRef.where("state", ">=", "CA").where("state", "= 字符串,我们在Stack O
我正在尝试检查一个字符串是否包含在另一个字符串中。后面的代码非常简单。我怎样才能在 jquery 中做到这一点? function deleteRow(locName, locID) { if
这个问题在这里已经有了答案: How to implement big int in C++ (14 个答案) 关闭 9 年前。 我有 2 个字符串,都只包含数字。这些数字大于 uint64_t 的
我有一个带有自定义转换器的 Dozer 映射: com.xyz.Customer com.xyz.CustomerDAO customerName
这个问题在这里已经有了答案: How do I compare strings in Java? (23 个回答) 关闭 6 年前。 我想了解字符串池的工作原理以及一个字符串等于另一个字符串的规则是
我已阅读 this问题和其他一些问题。但它们与我的问题有些无关 对于 UILabel 如果你不指定 ? 或 ! 你会得到这样的错误: @IBOutlet property has non-option
这两种方法中哪一种在理论上更快,为什么? (指向字符串的指针必须是常量。) destination[count] 和 *destination++ 之间的确切区别是什么? destination[co
This question already has answers here: Closed 11 years ago. Possible Duplicates: Is String.Format a
我有一个Stream一个文件的,现在我想将相同的单词组合成 Map这很重要,这个词在 Stream 中出现的频率. 我知道我必须使用 collect(Collectors.groupingBy(..)
我是一名优秀的程序员,十分优秀!