刚入门C,搞试验的,要做资料,写了个含水率的程序,有点小问题,求指导
mac系统,只能用Xcode写,下面是输出结果和程序,就是为什么重复程序时出现2行 “程序是否要继续执行(Y/N)”
程序是否要继续执行(Y/N)
y
请输入配合比序号:
1
砂的含水率:
4.3
碎石(1)含水率:
1.5
碎石(2)含水率:
1.0
输出水泥, 输出砂, 碎石(1), 碎石(2), 应加水含量, 外加剂 :
水泥 = 369
砂 = 717
碎石(1) = 238
碎石(2) = 945
应加水含量 = 121
外加剂 = 3.69
程序是否要继续执行(Y/N)
程序是否要继续执行(Y/N)
//
// main.c
// 含水率计算
//
// Created by Hu Keming on 13-3-26.
// Copyright (c) 2013年 Hu Keming. All rights reserved.
//
# include <stdio.h>
int round (float x)
{
x = x +0.5;
return x;
}
int main(void)
{
int i = 1;
char ch;
while (i == 1)
{
printf("程序是否要继续执行(Y/N)\n");
scanf("%c", &ch);
printf("\n");
if(ch == 'y' || ch == 'Y')
{
int val;
printf("请输入配合比序号: \n");
scanf("%d", &val);
float W1, W2, W3;
float S1, S2, S3;
int water;
switch (val)
{
case 1: //立柱、盖梁含、墙身(1)含水率 C30
{
int cement_1 = 369;
float additive_1 = 3.69;
printf("砂的含水率: \n");
scanf("%f", &W1);
printf("碎石(1)含水率: \n");
scanf("%f", &W2);
printf("碎石(2)含水率: \n");
scanf("%f", &W3);
S1 = 687 * (1 + W1*0.01);
S2 = 234 * (1 + W2*0.01);
S3 = 936 * (1 + W3*0.01);
S1 = round(S1);
S2 = round(S2);
S3 = round(S3);
water = 164 - ((S1 + S2 + S3) - 1857);
printf("输出水泥, 输出砂, 碎石(1), 碎石(2), 应加水含量, 外加剂 :\n");
printf("水泥 = %d\n", cement_1);
printf("砂 = %.f\n", S1);
printf("碎石(1) = %.f\n", S2);
printf("碎石(2) = %.f\n", S3);
printf("应加水含量 = %d\n", water);
printf("外加剂 = %.2f\n", additive_1);
break;
}
case 2: //桩基含水率 C25
{
int cement_2 = 380;
float additive_2 = 3.80;
printf("砂的含水率: \n");
scanf("%f", &W1);
printf("碎石(1)含水率: \n");
scanf("%f", &W2);
printf("碎石(2)含水率: \n");
scanf("%f", &W3);
S1 = 778 * (1 + W1*0.01);
S2 = 207 * (1 + W2*0.01);
S3 = 826 * (1 + W3*0.01);
S1 = round(S1);
S2 = round(S2);
S3 = round(S3);
water = 179 - ((S1 + S2 + S3) - 1811);
printf("输出水泥, 输出砂, 碎石(1), 碎石(2), 应加水含量, 外加剂 :\n");
printf("水泥 = %d\n", cement_2);
printf("砂 = %.f\n", S1);
printf("碎石(1) = %.f\n", S2);
printf("碎石(2) = %.f\n", S3);
printf("外加剂 = %.2f\n", additive_2);
break;
}
case 3: //系梁、墙身(2) C25
{
int cement_3 = 343;
float additive_3 = 2.74;
printf("砂的含水率: \n");
scanf("%f", &W1);
printf("碎石(1)含水率: \n");
scanf("%f", &W2);
printf("碎石(2)含水率: \n");
scanf("%f", &W3);
S1 = 696 * (1 + W1*0.01);
S2 = 237 * (1 + W2*0.01);
S3 = 949 * (1 + W3*0.01);
S1 = round(S1);
S2 = round(S2);
S3 = round(S3);
water = 165 - ((S1 + S2 + S3) - 1882);
printf("输出水泥, 输出砂, 碎石(1), 碎石(2), 应加水含量, 外加剂 :\n");
printf("水泥 = %d\n", cement_3);
printf("砂 = %.f\n", S1);
printf("碎石(1) = %.f\n", S2);
printf("碎石(2) = %.f\n", S3);
printf("应加水含量 = %d\n", water);
printf("外加剂 = %.2f\n", additive_3);
break;
}
case 4: //基础(1) C20
{
int cement_4 = 300;
float additive_4 = 2.40;
printf("砂的含水率: \n");
scanf("%f", &W1);
printf("碎石(1)含水率: \n");
scanf("%f", &W2);
printf("碎石(2)含水率: \n");
scanf("%f", &W3);
S1 = 733 * (1 + W1*0.01);
S2 = 239 * (1 + W2*0.01);
S3 = 957 * (1 + W3*0.01);
S1 = round(S1);
S2 = round(S2);
S3 = round(S3);
water = 161 - ((S1 + S2 + S3) - 1929);
printf("输出水泥, 输出砂, 碎石(1), 碎石(2), 应加水含量, 外加剂 :\n");
printf("水泥 = %d\n", cement_4);
printf("砂 = %.f\n", S1);
printf("碎石(1) = %.f\n", S2);
printf("碎石(2) = %.f\n", S3);
printf("应加水含量 = %.2f\n", additive_4);
break;
}
case 5: //基础(2) C15
{
int cement_5 = 267;
float additive_5 = 2.40;
printf("砂的含水率: \n");
scanf("%f", &W1);
printf("碎石(1)含水率: \n");
scanf("%f", &W2);
printf("碎石(2)含水率: \n");
scanf("%f", &W3);
S1 = 746 * (1 + W1*0.01);
S2 = 243 * (1 + W2*0.01);
S3 = 974 * (1 + W3*0.01);
S1 = round(S1);
S2 = round(S2);
S3 = round(S3);
water = 160 - ((S1 + S2 + S3) - 1963);
printf("输出水泥, 输出砂, 碎石(1), 碎石(2), 应加水含量, 外加剂 :\n");
printf("水泥 = %d\n", cement_5);
printf("砂 = %.f\n", S1);
printf("碎石(1) = %.f\n", S2);
printf("碎石(2) = %.f\n", S3);
printf("应加水含量 = %d\n", water);
printf("外加剂 = %.2f\n", additive_5);
break;
}
}
}
else if(ch == 'n' || ch == 'N')
break;
}
return 0;
}