| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 158 人关注过本帖
标题:关于计算器的使用
只看楼主 加入收藏
xcx901223
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2010-12-24
结帖率:100%
收藏
 问题点数:0 回复次数:0 
关于计算器的使用
#include <stdio.h>
static float sum=0,a=0,b=0,c=0,d=0,e=0,f=0;
float add(float op1,float op2)
{
    float m;
    printf("请输入一个数:\n");
    scanf("%d", &op1);
    printf("请输入另一个数:\n");
    scanf("%d", &op2);
    m=op1+op2;
    return(m);
}
float subtraction(float op1,float op2)
{   
    float n;
    printf("请输入一个数:\n");
    scanf("%d", &op1);
    printf("请输入另一个数:\n");
    scanf("%d", &op2);
    n=op1-op2;
    return(n);
}
float cheng(float op1,float op2)
{   
    float o;
    printf("请输入一个数:\n");
    scanf("%d", &op1);
    printf("请输入另一个数:\n");
    scanf("%d", &op2);
    o=op1*op2;
    return(o);
}
float chu(float op1,float op2)
{
    float p;
    printf("请输入一个数:\n");
    scanf("%d", &op1);
    printf("请输入另一个数:\n");
    scanf("%d", &op2);
    p=op1/op2;
    return(p);
}
void calculator()
{
   
    int y;
    float a,b,c,d;
    printf("请选择运算模式:\n");
    printf("1.加法\n");
    printf("\n");
    printf("2.减法\n");
    printf("\n");
    printf("3.乘法\n");
    printf("\n");
    printf("4.除法\n");
    scanf("%d",&y);
    switch(y)
    {
    case 1:a=float add(float,float);break;
    case 2:b=float subtraction(float,float);break;
    case 3:c=float cheng(float,float);break;
    case 4:d=float chu(float,float);break;
    default:printf ("输入错误!"); break;
    }
    printf("计算结果为:%.2f:\n");
}


void inquire()
{
    printf("支出如下:\n");
    printf("网 上 购 物 花 费:%.2f元:\n",a);
    printf("超市购物花费:%.2f元:\n",b);
    printf("吃饭花费:%.2f元:\n",c);
    printf("其他花费:%.2f元:\n",d);
    printf("\n");
    printf("收入如下:\n");
    printf("父母每月所给生活费:%.2f元:\n",e);
    printf("兼职所得:%.2f元:\n",f);
    printf("\n");
    printf("当前余额为:%.2f元:\n",sum);
    if(sum<0)
    {
        printf("0000000000000000000000000000000000000\n");     //感叹号表示已经超支!
        printf("000000000000000000 000000000000000000\n");
        printf("00000000000000000   00000000000000000\n");
        printf("0000000000000000     0000000000000000\n");
        printf("000000000000000       000000000000000\n");
        printf("000000000000000       000000000000000\n");
        printf("000000000000000       000000000000000\n");
        printf("000000000000000       000000000000000\n");
        printf("000000000000000       000000000000000\n");
        printf("000000000000000       000000000000000\n");
        printf("000000000000000       000000000000000\n");
        printf("000000000000000       000000000000000\n");
        printf("000000000000000       000000000000000\n");
        printf("000000000000000       000000000000000\n");
        printf("0000000000000000     0000000000000000\n");
        printf("00000000000000000   00000000000000000\n");
        printf("000000000000000000 000000000000000000\n");
        printf("0000000000000000000000000000000000000\n");
        printf("0000000000000000     0000000000000000\n");
        printf("0000000000000000     0000000000000000\n");
        printf("0000000000000000     0000000000000000\n");
        printf("0000000000000000000000000000000000000\n");
        printf("您已超支!\n");
    }
   
    else if(sum>100)
            printf("您的消费情况良好!\n");

         else
            {
                printf("请注意您的消费情况,有透支的危险!!!!!!\n");
            }
}

void income()
{
    float o,p,c=0;
    printf("父母每月所给生活费:\n");
    scanf("%f",&o);
    e=e+o;
    printf("兼职所得:\n");
    scanf("%f",&p);
    f=f+p;
    c=c+e+f;
    printf("当前收入总额:%.2f元\n",c);
    sum=sum+e+f;
}
void disburse()
{
    float g,h,i,j,k=0;
    printf("网上购物花费:\n",a);
    scanf("%f",&g);
    a=a+g;
    printf("超市购物花费:\n",b);
    scanf("%f",&h);
    b=b+h;
    printf("吃饭花费:\n",c);
    scanf("%f",&i);
    c=c+i;
    printf("其他花费:\n",d);
    scanf("%f",&j);
    d=d+j;
    k=k+a+b+c+d;
    printf("当前支出总额:%.2f元\n",k);
    sum=sum-a-b-c-d;
}
void account()
{
int x;
printf("***********************************\n");
printf("1.支出 2.进账 3.退出 4.查询余额\n");
printf("***********************************\n");
scanf("%d",&x);
switch(x)
{
  case 1:  disburse();break;
  case 2:  income();break;
  case 3:  printf("欢迎使用,再见!\n");break;
  case 4:  inquire();break;
}
}
void password()
{
    long int a;
    int b=1;
    do
    {
    printf("请输入密码!:\n");
    scanf("%d",&a);
    if(a==901223)
        {
        printf("密码输入正确,欢迎进入个人理财系统!\n\n\n\n\n");
        b=0;
        }
    else
        printf("密码输入错误!\n");
    }
    while(b);
}
void main()
{
password();
loop: int x;
printf("\n                ***********************************************\n");
printf("\n");
printf("\n                   个 人 理 财 系 统 1.0       by xiaochenxi\n");
printf("\n");
printf("\n                ***********************************************\n");
printf("\n");
printf("\n");
printf("                  请选择管理项目:\n");
printf("\n");
printf("                  1.详细账目输入\n");
printf("\n");
printf("                  2.查询当前余额\n");
printf("\n");
printf("                  3.小工具(计算器)\n");
printf("\n");
printf("                  4.退出\n");
scanf("%d",&x);
    switch(x)
    {
        case 1: account();goto loop;break;
        case 2: inquire();goto loop;break;
        case 3: calculator();goto loop;break;
        case 4: printf ("欢迎再次使用,再见!"); break;
        default:printf ("输入错误!"); break;
    }
}
2010-12-30 14:36
快速回复:关于计算器的使用
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.036816 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved