{
  "question_id": 7412708,
  "question_title": "水果计费系统",
  "question_content": "<p>本关任务&#xff1a;编写程序&#xff0c;有五种水果&#xff0c;apple、banana、orage、strawberry、pear&#xff0c;每一种有一个价格&#xff08;浮点小数&#xff09;&#xff0c;由老板输入&#xff0c;请提示用户选择什么水果&#xff0c;购买数量&#xff08;按照斤两&#xff09;&#xff0c;然后将总价显示出来。</p>",
  "difficulty": "简单",
  "answer_id": 53364151,
  "answer_content": "<pre>\n<code>#include&lt;stdio.h&gt;\n\nint main(){\n\ttypedef enum {apple, banana, orange, strawberry, pear} fruits;//水果枚举类型 \n\tdouble prices[5];             //价格数组\n\tfruits purchase;             //枚举购买水果 \n\tint fruit;                   //水果编号的输入 \n\tdouble amount;               //总价 \n\tfor(int i &#61; 0; i &lt; 5; i&#43;&#43;)\n\t\tscanf(&#34;%lf&#34;, &amp;prices[i]);//老板输入价格 \n\tprintf(&#34;水果编号&#xff1a;1.苹果  2.香蕉  3.橘子  4.草莓  5.梨\\n&#34;);\n\tprintf(&#34;请输入购买的水果(1~5)&#xff0c;以及购买数量&#xff08;按照斤两&#xff09;&#xff1a;\\n&#34;);//提示\n\tscanf(&#34;%d %lf&#34;, &amp;fruit, &amp;amount);\n\tpurchase &#61; (fruits)fruit;     //输入的编号对应水果 \n\tprintf(&#34;总价为&#xff1a;%.3lf&#34;, prices[purchase-1]*amount);\n\treturn 0; \n}</code></pre>\n\n<p> </p>",
  "tag_name": "c语言",
  "cpp": "#include<stdio.h>\nint main(){\n\ttypedef enum {apple, banana, orange, strawberry, pear} fruits;\n\tdouble prices[5];\t\t\t \n\tfruits purchase;\t\t\t \n\tint fruit;\t\t\t\t   \n\tdouble amount;\t\t\t   \n\tfor(int i = 0; i < 5; i++)\n\t\tscanf(\"%lf\", &prices[i]);\n\tprintf(\"水果编号：1.苹果  2.香蕉  3.橘子  4.草莓  5.梨\\n\");\n\tprintf(\"请输入购买的水果(1~5)，以及购买数量（按照斤两）：\\n\");\n\tscanf(\"%d %lf\", &fruit, &amount);\n\tpurchase = (fruits)fruit;\t \n\tprintf(\"总价为：%.3lf\", prices[purchase-1]*amount);\n\treturn 0; \n}",
  "topic_link": "https://bbs.csdn.net/topics/600470173",
  "status": 1,
  "keywords": "算法中阶,贪心算法,活动选择问题,高级设计和分析技术",
  "license": "csdn.net",
  "notebook": {
    "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/98.ipynb?type=file"
  },
  "notebook_enable": 1,
  "author": "m0_45801658"
}