用C语言进行公英单位转换方法

试着写了一下单位转换,写的很粗糙

为什么是英文?因为用英文用的比较习惯

#define _CRT_SECURE_NO_WARNINGS 
#include <stdlib.h>
#include <string.h>
#include<stdio.h>
#include <math.h>
#include "string.h"

//imperial unit
float twipvalua(float a) {
	float b = a * 0.0000176389;
	return b;
}
float thouvalua(float a) {
	float b = a * 0.0000254;
	return b;
}
float barlycornvalua(float a) {
	float b = a * 0.0084667;
	return b;
}
float inchvalua(float a) {
	float b = a * 0.0254;
	return b;
}
float handvalua(float a) {
	float b = a * 0.1016;
	return b;
}
float footvalua(float a) {
	float b = a * 0.3048;
	return b;
}
float yardvalua(float a) {
	float b = a * 0.9144;
	return b;
}
float chainvalua(float a) {
	float b = a * 20.1168;
	return b;
}
float furlongvalua(float a) {
	float b = a * 201.168;
	return b;
}
float milevalua(float a) {
	float b = a * 1609.344;
	return b;
}
float leaguevalua(float a) {
	float b = a * 4828.032;
	return b;
}
float fathomvalua(float a) {
	float b = a * 185.2;
	return b;
}
float cablevalua(float a) {
	float b = a * 1.852;
	return b;
}
float nauticalmilevalua(float a) {
	float b = a * 1852;
	return b;
}
float linkvalua(float a) {
	float b = a * 0.201168;
	return b;
}
float rodvalua(float a) {
	float b = a * 5.0292;
	return b;
}
//metric unit
float dmvalua(float a) {
	float b = a / 10;
	return b;
}
float cmvalua(float a) {
	float b = a / 1000;
	return b;
}
float mmvalua(float a) {
	float b = a / 1000000;
	return b;
}
float nmvalua(float a) {
	float b = a / 1.0000E9;
	return b;
}
float pmvalua(float a) {
	float b = a / 1.0000E12;
	return b;
}
float fmvalua(float a) {
	float b = a / 1.0000E15;
	return b;
}
float amvalua(float a) {
	float b = a / 1.0000E18;
	return b;
}
float zmvalua(float a) {
	float b = a / 1.0000E21;
	return b;
}
float ymvalua(float a) {
	float b = a / 1E24;
	return b;
}
float damvalua(float a) {
	float b = a * 10;
	return b;
}
float hmvalua(float a) {
	float b = a * 100;
	return b;
}
float kmvalua(float a) {
	float b = a * 1000;
	return b;
}
float Mmvalua(float a) {
	float b = a * 1000000;
	return b;
}
float Gmvalua(float a) {
	float b = a * 1.0000E9;
	return b;
}
float Tmvalua(float a) {
	float b = a * 1.0000E12;
	return b;
}
float Pmvalua(float a) {
	float b = a * 1.0000E15;
	return b;
}
float Emvalua(float a) {
	float b = a * 1.0000E18;
	return b;
}
float Zmvalua(float a) {
	float b = a * 1.0000E21;
	return b;
}
float Ymvalua(float a) {
	float b = a * 1.0000E24;
	return b;
}

int main() {

	float a; //valua
	float c;
	char b[50] = { 0 }; //userinput
	char b2[50] = { 0 };
	//imperial unit
	int  twip;
	int  twips;
	int  twipss;
	int  thou;
	int  thous;
	int  barleycorn;
	int  barleycorns;
	int  inch;
	int  inchs;
	int  inchss;
	int  inchsss;
	int  inchssss;
	int  hand;
	int  hands;
	int  handss;
	int  foot;
	int  foots;
	int  footss;
	int  footsss;
	int  yard;
	int  yards;
	int  yardss;
	int  chain;
	int  chains;
	int  chainss;
	int  furlong;
	int  furlongs;
	int  furlongss;
	int  mile;
	int  miles;
	int  miless;
	int  league;
	int  leagues;
	int  leaguess;
	int  fathom;
	int  fathoms;
	int  fathomss;
	int  cable;
	int  cables;
	int  nauticalmile;
	int  nauticalmiles;
	int  nauticalmiless;
	int  link;
	int  links;
	int  rod;
	int  rods;
	//metric unit
	int  dm;
	int  dms;
	int  cm;
	int  cms;
	int  mm;
	int  mms;
	int  um;
	int  ums;
	int  nm;
	int  nms;
	int  pm;
	int  pms;
	int  fm;
	int  fms;
	int  am;
	int  ams;
	int  zm;
	int  zms;
	int  ym;
	int  yms;
	int  dam;
	int  dams;
	int  hm;
	int  hms;
	int  km;
	int  kms;
	int  Mm;
	int  Mms;
	int  Gm;
	int  Gms;
	int  Tm;
	int  Tms;
	int  Pm;
	int  Pms;
	int  Em;
	int  Ems;
	int  Zm;
	int  Zms;
	int  Ym;
	int  Yms;

	
	
		printf("Enter a real-number distance Followed by unit name\n");
		printf("\n");
		printf("Distance: ");
		int ret = scanf("%f ", &a);
		gets(b);
		strcpy(b2, b);
		strcpy(b, b);
		int valua = 2;
		char f;

		int M = 50;
		for (int i = 0; b[i] != '\0'; i++) 
		for (int i = 0; i < M; i++)
		{
			if (b[i] >= 65 && b[i] <= 90)
			{
				b[i] += 32;
			}
		}
		
		//Use the strcmp function to ensure that the input is correct
		twip = strcmp(b, "twip");
		twips = strcmp(b, "th");
		twipss = strcmp(b, "twips");
		thou = strcmp(b, "thou");
		thous = strcmp(b, "thous");
		barleycorn = strcmp(b, "barleycorn");
		barleycorns = strcmp(b, "Bc");
		inch = strcmp(b, "inch");
		inchs = strcmp(b, "in");
		inchss = strcmp(b, "\"");
		inchsss = strcmp(b, "inchs");
		inchssss = strcmp(b, "inches");
		hand = strcmp(b, "hand");
		hands = strcmp(b, "h");
		handss = strcmp(b, "hands");
		foot = strcmp(b, "foot");
		foots = strcmp(b, "ft");
		footss = strcmp(b, "'");
		footsss = strcmp(b, "feet");
		yard = strcmp(b, "yard");
		yards = strcmp(b, "yd");
		yardss = strcmp(b, "yards");
		chain = strcmp(b, "chain");
		chains = strcmp(b, "ch");
		chainss = strcmp(b, "chains");
		furlong = strcmp(b, "furlong");
		furlongs = strcmp(b, "fur");
		furlongss = strcmp(b, "furlongs");
		mile = strcmp(b, "mile");
		miles = strcmp(b, "mi");
		miless = strcmp(b, "miles");
		league = strcmp(b, "league");
		leagues = strcmp(b, "lea");
		leaguess = strcmp(b, "leagues");
		fathom = strcmp(b, "fathom");
		fathoms = strcmp(b, "ftm");
		fathomss = strcmp(b, "fathom
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值