跪求c语言程序设计之书店图书销售系统

跪求c语言程序设计之书店图书销售系统,第1张

#include "stdio.h"

#include "string.h"

#define N 1000

struct book

{char author[10]

char bkname[20]

float price

int num

}

int n

bkin(struct book bk[])

{

char ath[10],bknm[20]

float pr

int nm,i

clrscr()

printf("Input BookName BookAuthor Price Number:\n")

scanf("%s%s%f%d",ath,bknm,&pr,&nm)

for (i=0i<ni++)

if ( strcmp(bk[i].bkname,bknm)==0 ) break

if (i<n) bk[i].num+=nm

else

{

strcpy(bk[n].author,ath)

strcpy(bk[n].bkname,bknm)

bk[n].price=pr

bk[n].num = nm

n++

}

printf("Book In ok...\n")

}

bksale(struct book bk[])

{

clrscr()

printf("Book Sale....\n")

}

bklist(struct book bk[])

{

int i

clrscr()

printf("Book List:\n\n")

printf("Author BookName Price BookNumber\n")

printf("------------------------------------------------------\n")

for (i=0i<ni++)

printf("%-10s %-20s %-10.2f %-5d\n",bk[i].author,

bk[i].bkname,bk[i].price,bk[i].num)

}

show()

{clrscr()

printf("\n\n\n\n\n")

printf(" ----------------------------------------------------\n")

printf(" 1.BookIn\n")

printf(" 2.Booksale\n")

printf(" 3.BookList\n")

printf(" 4.Exit\n")

printf(" ----------------------------------------------------\n")

printf(" Please select 1.2.3.4:\n")

}

main()

{

struct book bk[N]

int select

strcpy(bk[0].author,"Tom")

strcpy(bk[0].bkname,"Bookname1")

bk[0].price=20.00

bk[0].num = 10

strcpy(bk[1].author,"Jerry")

strcpy(bk[1].bkname,"Bookname2")

bk[1].price=12.00

bk[1].num = 3

n=2

show()

scanf("%d",&select)

while(select != 4)

{ if (select == 1) bkin(bk)

if (select == 2) bksale(bk)

if (select == 3) bklist(bk)

getch()

show()

scanf("%d",&select)

}

}

1 涉及的C语言知识

(1)输入

(2)加减乘除运算

(3)输出

2 一个小示例

#include<stdio.h>

float get_discount(int x){

    float output = 0

    //当输入以0结尾时,不合法,返回0

    if (x % 10 == 0)

        return output

    //当输入为 85 时,代表85折,输出应为0.85

    if (x > 10 && x < 100)

        output = x / 100.0

    //当输入为 7 时,代表7折,输出应为0.7

    if (x < 10 && x >= 1)

        output = x / 10.0

    return output

}

int main(){

    float count

    int discount_str

    puts("输入书的金额和打印情况(以空格为分割符,按回车结束):")

    puts("(如输入的是20 7则表示20元的书打7折)")

    scanf("%f %d", &count, &discount_str)

    float discount_f = get_discount(discount_str)

    if (discount_f == 0)

        puts("输入的打折情况不合法.")

    else{

        float result = count*discount_f

        printf("打折后的金额为:%.2f\n", result)

    }

    getchar()

    getchar()

    return 0

}

3 运行情况


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11426264.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-16
下一篇 2023-05-16

发表评论

登录后才能评论

评论列表(0条)

保存