我真的不太了解c程序,所以真的需要你的帮助.. 这是找到输入值日(例如1583.3.31 - >星期四)和打印"错误的年/月/日"如果是无效日期。 我写了回报0;在中间部分,因为当日期无效时我必须离开这个。我查了一下。但是,当日期有效时(例如1583.3.31),它不会进入下一部分(如果数字有效则应该打印日)它只是结束程序。我想知道为什么:(
#include <stdio.h>
int main(void) {
int year, month, day;
printf("Enter Gregorian year (year >= 1583): ");
scanf("%d", &year);
printf("Enter Gregorian month (month: 1..12): ");
scanf("%d", &month);
printf("Enter Gregorian day (1..28|29|30|31): ");
scanf("%d", &day);
{if (month < 1 || month > 12)
printf("Wrong month! Try again!");
if (year < 1583)
printf("Enter year >= 1583! Try again!");
if (day < 1 || day > 31)
printf("Wrong day! Try again!");
if (month == 4 && (day < 1 || day > 30))
printf("Wrong day! Try again!");
if (month == 6 && (day < 1 || day > 30))
printf("Wrong day! Try again!");
if (month == 9 && (day < 1 || day > 30))
printf("Wrong day! Try again!");
if (month == 11 && (day < 1 || day > 30))
printf("Wrong day! Try again!");
if (month == 2){
if (year % 4 == 0 && (day < 1 || day > 29))
printf("Wrong day! Try again!");
if (year % 100 == 0 && (day < 1 || day > 28))
printf("Wrong day! Try again!");
if (year % 400 == 0 && (day < 1 || day > 29))
printf("Wrong day! Try again!");}
else if (month == 2 && (day < 1 || day > 28))
printf("Wrong day! Try again!");
return 0;}
year += 8000;
if (month < 3) { year--; month += 12; }
long julian = (year*365) + (year/4) - (year/100) + (year/400) - 1200820 + (month*153+3)/5 - 92 + (day-1);
switch(julian % 7){
case 0:
printf("%d-%d-%d is Monday", year -= 8000, month, day);
break;
case 1:
printf("%d-%d-%d is Tuesday", year -= 8000, month, day);
break;
case 2:
printf("%d-%d-%d is Wednesday", year -= 8000, month, day);
break;
case 3:
printf("%d-%d-%d is Thursday", year -= 8000, month, day);
break;
case 4:
printf("%d-%d-%d is Friday", year -= 8000, month, day);
break;
case 5:
printf("%d-%d-%d is Saturday", year -= 8000, month, day);
break;
case 6:
printf("%d-%d-%d is Sunday", year -= 8000, month, day);
break;}
return 0;
}
答案 0 :(得分:0)
import SpriteKit
public class PKTexturedLabelNode : SKSpriteNode{
fileprivate let embeddedLabel : SKLabelNode
fileprivate var rasterizingView : SKView? {
if let rasterizeInView = rasterizeInView {
return rasterizeInView
} else {
return scene?.view
}
}
public var rasterizeInView : SKView?
public required init?(coder aDecoder: NSCoder) {
embeddedLabel = SKLabelNode()
super.init(coder: aDecoder)
}
public init(fontNamed: String?){
embeddedLabel = SKLabelNode(fontNamed: fontNamed)
super.init(texture: nil, color: SKColor.white, size: CGSize(width: 0, height: 0))
}
public init(text:String?){
embeddedLabel = SKLabelNode(text: text)
super.init(texture: nil, color: SKColor.white, size: CGSize(width: 0, height: 0))
}
var fontName : String? {
get {
return embeddedLabel.fontName
}
set {
embeddedLabel.fontName = newValue
render()
}
}
var fontSize : CGFloat {
get {
return embeddedLabel.fontSize
}
set {
embeddedLabel.fontSize = newValue
render()
}
}
var text : String? {
get {
return embeddedLabel.text
}
set {
embeddedLabel.text = newValue
render()
}
}
fileprivate func render(){
if let texture = rasterizingView?.texture(from: embeddedLabel){
texture.filteringMode = .nearest
size = texture.size()
self.texture = texture
}
}
}
语句后您有一个无条件return 0;
。除第一个if
之外的所有内容都应为if
,并且正确日期的代码应位于else if
块中。或者,在每个错误案例结束时返回,仅在每个检查通过时继续进行 - 尽管这会导致大量重复。
将所有这些语句包含在一组括号中只会为变量声明创建一个词法范围,可能不是你的意思。
检查有效性的代码可能是else
... do
循环,在您输入无效日期时重试,并且您应该在经历该循环后计算一周中的某一天,这将在日期有效时发生。