個人是這樣: int main(void) { int customers, cos ; printf("How many customers:") ; scanf("%d", &customers) ; cos = customers * 300 ; if (cos < 3000) { printf(" Total:%d ", cos); } int total ; int temp = cos ; if (cos >= 3000) { printf(" Cos:%d ", cos); cos = cos - (cos * 0.8) ; printf(" Discount:%d ", cos); total = temp - cos ; printf(" Total:%d", total); } return 0 ; }
謝謝老師用心的課程編排 #include int main() { int people,number,sum; people = 300; printf("滿三千打八折活動,每人三百,請輸入人數:"); scanf("%d", &number); sum = people * number; if( sum >= 3000){ sum = sum*0.8; printf("本次費用:%d元", sum); } if( sum < 3000){ printf("本次費用:%d元", sum); } return 0; }
我自己看書都看無,看老師的課有如打通任督二脈 以下我用一個變數,不知道這樣有沒有問題 #include int main(){ int number; printf("Please enter the number of customers:"); scanf("%d", &number); number = 300*number; if (number>=3000){ number = number *0.8; } printf("Total:%d ", number); return 0; }
没有听完做的,结果我用了人数的计算方法,算第四种解法吧XD #include int main (){ int number, total; printf ("please enter the number of customers:"); scanf ("%d",&number); if (number < 10){ total = 300*number; } if (number >= 10){ total = 300*number*0.8; } printf ("total: %d ",total); return 0; }
聽到一半在猜if怎麼寫時, 誤打誤撞好像寫對了 #include int main () { int number, total; printf("please enter the numbers of customers: "); scanf("%d", &number); total = number*300; if (total >= 3000) { total = 300* number * 0.8; } printf("Total: %d ", total); return 0; }
include int main() { int number,totel; printf("please enter the number of customers"); scanf("%d", &number); if (number 15) { totel = 300 * number * 0.8; } printf("totel: %d", totel); return 0; }
#include int main () { int per_price = 300; int per_cust; int consume = 3000; int Multi; int discount = 0; int total; printf("Please enter the number of customer: "); scanf("%d", &per_cust); Multi = per_price * per_cust; if (Multi > consume); { discount = 8; total = (Multi * discount) /100; total = Multi - total; printf("Total:%d", total); } return 0; } 哈哈,我先自己做了先,然后再看老师的,做法果然不同T-T, 但还是能算出答案
#include int main () { int per_price = 300; int per_cust; int consume = 3000; int Multi; int discount = 8; int total; printf("Please enter the number of customer: "); scanf("%d", &per_cust); Multi = per_price * per_cust; if (Multi < consume) { total = Multi; } if (Multi >= consume) { total = (Multi * discount) /100; total = Multi - total; } printf("Total:%d", total); return 0; } 这个才对 早上睡醒,发现自己的code有问题 1. 没超过3000,也打折 2. if后面是不需要 “;” 3.printf不能放在if {} 的里面
#include int main (){ int Anzahl ,Geld; printf(" Anzahl: "); scanf("%d",&Anzahl); if (Anzahl 9){ Geld=240*Anzahl; printf("Kosten ist %d\.n ",Geld); } return 0; }
#include int main(){ int customers,total; printf("Please enter the number of customers: "); scanf("%d",&customers); if(customers>=10){ total=customers*300*0.8; } if(customers
#include int main(){ int people; int total; printf("Please enter the customer number:" ); scanf("%d",&people); total = people * 300; if(total>=3000){ total = total * 0.8; } if(total
#include int main(){ int number,Total; printf("Please enter the number of customers:"); scanf("%d",&number); Total=number*300; if(number>=10){ Total=number*300*0.8; } printf("Total:%d ",Total); return 0; } 我想的比較簡單XD
#include int main() { int People, Total; printf("Please enter the number of people : "); scanf("%d", &People); Total = People * 300; if (Total >= 3000) { Total = Total * 0.8; } printf("Total : %d ", Total); return 0; } 我的比較少一點XDDDD但是好像沒差
#include int main (){ int a,total; printf("please enter the number of customers:"); scanf("%d",&a); total=a*300; if(a>=10){ total=a*300*0.8; } printf("total:%d ",total); return 0; } 我觉得这样会更简单点
您好 不好意思 我想請問一下 #include int main () { int person; printf("Please enter today how many people:"); scanf("%d",&person); if (person < 10 ){ printf("Today's cost is %d",300 * person); } if (person >= 10){ printf("Today's cost is %d ",300 * person * 0.8);} return 0; } 我這樣執行 但是如果我輸入人數超過10人的話 最後輸出的結果都會變成0 想知道是哪邊出了問題 麻煩您了 謝謝
這打法也可以吧 #include int main(){ int person; printf("Number of guests at this table:"); scanf("%d", &person); int total = person*300; if(person < 10){ printf("The price is:%d", total); } if(person >= 10){ total *= 0.8; printf("Total:%d", total); } return 0; }
//注意型別轉換 #include int main(){ int number, original; printf("Please enter the number of customers: "); scanf("%d", &number); original = number * 300; if(original >= 3000){ printf("Total is %d", (int)(original * 0.8)); } if(original < 3000){ printf("Total is %d", original); } return 0; }
#include int main(){ int number, total; printf("Please enter the number of customers: "); scanf("%d", &number); total = 300 * number; if(total >= 3000){ total *= 0.8; } printf("Total: %d ", total); return 0; }
#include int main() { int customers , total ; printf("Please enter the number of customers : "); scanf("%d",& customers); if (customers >= 10){ total = customers*0.8*300 ; printf("Total is %d. ",total); } if (customers >= 0 && customers < 10){ total = customers*300 ; printf("Total is %d. ",total); } return 0; }
#include int main () { int a; printf("please enter the number of customers: "); scanf("%d", &a); if(a >= 10) { a = a * 300 * 0.8; } if(a < 10) { a = a * 300; } printf("total:%d ", a); return 0; } my attempt
2022還在看老師的優秀教學
超級懂用由淺入深方式教學的老師,看老師視頻既可以學程式又可是學教學方式,Feis Studio頻道超讚!
非常精彩的課程編排
三種寫法的呈現順序
看似簡單直觀實際上是精心巧妙的安排
第三種方法節省了CPU&RAM。謝謝指導
留言中有人問想四捨五入怎麼做
我就用目前學到的 寫了一個小程式
只有五個步驟 想跟大家分享 還望老師賜教
1宣告一個浮點數number1
讓使用者自由輸入
2宣告一個整數number2
number2 = number1 就得到一個無條件捨去的整數
3宣告一個浮點數number3
number3 = number1 - number2 就得到了純小數
4使用if述句
if number3 >= 0.5
則 number2 = number2 + 1
5輸出number2 完成!
好棒,好棒,更新了。。。。up主辛苦了
讲的非常清楚,感谢老师!
個人是這樣:
int main(void)
{
int customers, cos ;
printf("How many customers:") ;
scanf("%d", &customers) ;
cos = customers * 300 ;
if (cos < 3000)
{
printf(" Total:%d
", cos);
}
int total ;
int temp = cos ;
if (cos >= 3000)
{
printf(" Cos:%d
", cos);
cos = cos - (cos * 0.8) ;
printf(" Discount:%d
", cos);
total = temp - cos ;
printf(" Total:%d", total);
}
return 0 ;
}
想請問老師,再看到後面之前我有先嘗試思考試著寫,在19:42的地方 if(total >= 3000){total = total*0.8},我本來只寫{total*0.8}的話就不會執行,是否原因是因爲算完之後結果沒有存回total,所有以才沒有效果呢?
因為你後面沒加;
謝謝老師用心的課程編排
#include
int main()
{
int people,number,sum;
people = 300;
printf("滿三千打八折活動,每人三百,請輸入人數:");
scanf("%d", &number);
sum = people * number;
if( sum >= 3000){
sum = sum*0.8;
printf("本次費用:%d元", sum);
}
if( sum < 3000){
printf("本次費用:%d元", sum);
}
return 0;
}
我覺得一個變數對新手來說比較好掌控
#include
int main()
{
int a = 0;
我自己看書都看無,看老師的課有如打通任督二脈
以下我用一個變數,不知道這樣有沒有問題
#include
int main(){
int number;
printf("Please enter the number of customers:");
scanf("%d", &number);
number = 300*number;
if (number>=3000){
number = number *0.8;
}
printf("Total:%d
", number);
return 0;
}
我是這樣子寫的
#include
int main()
{
int people;
int money = 300;
int sum;
printf("Please enter People: ");
scanf("%d", &people);
if(people >= 10){
sum = (money * people) * 0.8;
}
if(people < 10 ){
sum = money * people;
}
printf("Total money is %d.", sum);
}
我是用人數去判斷要不要打折這件事情,這樣算我邏輯上有進入誤區嗎?會超3000代表>=10個人,所以判斷人數去做打折。
請問我這樣寫有沒有什麼盲點呢?
因為也算得出來...
#include
int main () {
int number, Total1, Total2 ;
printf ("輸入顧客數量 : ") ;
scanf ("%d" , &number) ;
Total1 = number*300 ;
Total2 = number*300*0.8;
if (number < 10 ) {
printf ("Total : %d
", Total1);
}
if (number >= 10) {
printf ("Total : %d
", Total2);
}
return 0 ;
}
雖然最後結果一樣,但我覺得這和原本的題意"滿額折扣"不太一樣,你這比較像"消費滿多少人有打折" 的意思
int main(){
int a, b, c;
printf("請輸入客人數:");
scanf("%d" ,&a);
b =c = a * 300;
if (b >=3000) {
c = b * 0.8;
}
printf("總共%d元" ,c);
return 0;
}
表达式里有0.8,编译器提示有浮点数,要求定义变数total要为float or double,除了直接算出300*0.8以外,还有什么解决方法?
int main()
{
int pn,discount;
printf("请输入人数:");
scanf("%d", &pn);
if (pn < 10)
{
discount = pn * 300;
printf("应付金额为:%d
", discount);
}
if (pn >= 10)
{
discount = pn * 240;
printf("应付金额为:%d
", discount);
}
return 0;
}
*8/10
+Mingming Hui double discount
int main(){
int x,money;
printf("number:");
scanf("%d",&x);
money=x*300;
if(money>=3000){
printf("total:%f",money*0.8);
}
if(money
money*0.8乘出來的值都會是整數,所以用%d比較合適
没有听完做的,结果我用了人数的计算方法,算第四种解法吧XD
#include
int main (){
int number, total;
printf ("please enter the number of customers:");
scanf ("%d",&number);
if (number < 10){
total = 300*number;
}
if (number >= 10){
total = 300*number*0.8;
}
printf ("total: %d
",total);
return 0;
}
Y Z 哈哈跟我一樣欸
這只是換單位而已吧
@@大大帥-k4r 意義已經不同了,只是結果剛好一樣,且必須要在已知(人數達十人時會超過3000元),所以會變成人數超過十人時打八折,而不是原本的超過3000打八折。
如果在不確定條件時,可能出現無法預期的問題。
聽到一半在猜if怎麼寫時, 誤打誤撞好像寫對了
#include
int main ()
{
int number, total;
printf("please enter the numbers of customers: ");
scanf("%d", &number);
total = number*300;
if (total >= 3000) {
total = 300* number * 0.8;
}
printf("Total: %d
", total);
return 0;
}
我一開始設成浮點數來算,結果都會變成0.000000,是整數不能 x 0.8 嗎?
include
int main() {
int number,totel;
printf("please enter the number of customers");
scanf("%d", &number);
if (number 15) {
totel = 300 * number * 0.8;
}
printf("totel: %d", totel);
return 0;
}
我是這樣打:P
#include
int main() {
printf("
\t滿額打8折
");
int a, b;
printf(" \t請輸入應付價格:");
scanf("%d", &a);
if(a>=3000){ //如果應付價格高於3000就...
b = a * 0.8;
printf("
應付:
%d元", b);
}else printf("
應付:
%d元", a);
return 0;
}
可以問一下為什麼printf 中總是習慣要換行(加
)
增加可讀性
printf("这个太酷了!");
Total定義為int
但打折後的數值可能會有小數,倘若最後想要四捨五入該如何處理呢?
那就定义为double 你没看前面的课程咩
#include
int main()
{
int num;
double total;
printf("Please inter the integer:
");
scanf("%d",&num);
total=(double)num*(double)300;
if(total>3000)
{
total=total*0.8;
printf("%f
",total);
}else
{
printf("%f
",total);
}
return 0;
}
依照題意 total*0.8 不會有小數的情況發生吧?
你的價格應該不會有小數吧?除非你用美元XD
#include
int main () {
int per_price = 300;
int per_cust;
int consume = 3000;
int Multi;
int discount = 0;
int total;
printf("Please enter the number of customer: ");
scanf("%d", &per_cust);
Multi = per_price * per_cust;
if (Multi > consume); {
discount = 8;
total = (Multi * discount) /100;
total = Multi - total;
printf("Total:%d", total);
}
return 0;
}
哈哈,我先自己做了先,然后再看老师的,做法果然不同T-T, 但还是能算出答案
#include
int main () {
int per_price = 300;
int per_cust;
int consume = 3000;
int Multi;
int discount = 8;
int total;
printf("Please enter the number of customer: ");
scanf("%d", &per_cust);
Multi = per_price * per_cust;
if (Multi < consume) {
total = Multi;
}
if (Multi >= consume) {
total = (Multi * discount) /100;
total = Multi - total;
}
printf("Total:%d", total);
return 0;
}
这个才对
早上睡醒,发现自己的code有问题
1. 没超过3000,也打折
2. if后面是不需要 “;”
3.printf不能放在if {} 的里面
#include
int main (){
int Anzahl ,Geld;
printf(" Anzahl: ");
scanf("%d",&Anzahl);
if (Anzahl 9){
Geld=240*Anzahl;
printf("Kosten ist %d\.n ",Geld);
}
return 0;
}
假設有5人來吃,其中有3人吃3,份,有2人吃2份
該如何寫程式
0.8不是浮點數嗎 為什麼可以直接乘
在某些情況下確實會出問題,可以試著設計出一組數字:乘上0.8之後因為出現小數點而改變資料型態,無法輸出。
#include
int main(){
int customers,total;
printf("Please enter the number of customers: ");
scanf("%d",&customers);
if(customers>=10){
total=customers*300*0.8;
}
if(customers
紀錄這是我學程式的第三天
#include
int main(){
int people;
int total;
printf("Please enter the customer number:" );
scanf("%d",&people);
total = people * 300;
if(total>=3000){
total = total * 0.8;
}
if(total
太不合理了,9個人的上哪說理去,10個人的都比它便宜
#include
int main()
{
int p,c;
printf("输入人数:
");
scanf("%d",&p);
c=p*300;
if(c>3000){c=(c*0.8);};
printf("金额为:%d.
",c);
return 0;
}
#include
int main()
{ int a;
printf("请输入人数:");
scanf("%d",&a);
if(a>10){printf("你的消费为:%d",a=a*240);}
if(a
可以省略掉 a=
#include
int main()
{ int a;
printf("请输入人数:");
scanf("%d",&a);
if(a>10){printf("你的消费为:%d",a*240);}
if(a
#include
int main(){
int number,Total;
printf("Please enter the number of customers:");
scanf("%d",&number);
Total=number*300;
if(number>=10){
Total=number*300*0.8;
}
printf("Total:%d
",Total);
return 0;
}
我想的比較簡單XD
@顧文凱 可能是因為最後一個printf沒有放在大括弧裡吧
2024/7/26簽到
#include
int main()
{
int People, Total;
printf("Please enter the number of people : ");
scanf("%d", &People);
Total = People * 300;
if (Total >= 3000) {
Total = Total * 0.8;
}
printf("Total : %d
", Total);
return 0;
}
我的比較少一點XDDDD但是好像沒差
👍
“%d” 是什么意思啊
你要去看前面有教完整的
先回答你%d=十位數有號整數
#include
int main (){
int a,total;
printf("please enter the number of customers:");
scanf("%d",&a);
total=a*300;
if(a>=10){
total=a*300*0.8;
}
printf("total:%d
",total);
return 0;
}
我觉得这样会更简单点
閹割版
#include
int main() {
int money ,pay;
printf("You spent money:");
scanf("%d", &money);
if(money>=3000) {
pay=money*8/10;
}
if(money
有點啰嗦,有很多前面講過的使用方法,一直在又重複講多很多遍。難受
[x . X]
免費的還嫌==傻眼
= = 你覺得教得慢可以自己快轉啊 囉嗦個毛阿
傻眼,不想聽可以快轉,老師教的很清楚
低能兒..
回家喝奶 傻x
您好 不好意思 我想請問一下
#include
int main ()
{
int person;
printf("Please enter today how many people:");
scanf("%d",&person);
if (person < 10 ){
printf("Today's cost is %d",300 * person);
}
if (person >= 10){
printf("Today's cost is %d
",300 * person * 0.8);}
return 0;
}
我這樣執行
但是如果我輸入人數超過10人的話
最後輸出的結果都會變成0 想知道是哪邊出了問題
麻煩您了 謝謝
把 300 * person * 0.8 改為 240 * person 就不會有問題了
可以想想看為甚麼
這打法也可以吧
#include
int main(){
int person;
printf("Number of guests at this table:");
scanf("%d", &person);
int total = person*300;
if(person < 10){
printf("The price is:%d", total);
}
if(person >= 10){
total *= 0.8;
printf("Total:%d", total);
}
return 0;
}
//注意型別轉換
#include
int main(){
int number, original;
printf("Please enter the number of customers: ");
scanf("%d", &number);
original = number * 300;
if(original >= 3000){
printf("Total is %d", (int)(original * 0.8));
}
if(original < 3000){
printf("Total is %d", original);
}
return 0;
}
#include
int main(){
int number, total;
printf("Please enter the number of customers: ");
scanf("%d", &number);
total = 300 * number;
if(total >= 3000){
total *= 0.8;
}
printf("Total: %d
", total);
return 0;
}
#include
int main() {
int customers , total ;
printf("Please enter the number of customers : ");
scanf("%d",& customers);
if (customers >= 10){
total = customers*0.8*300 ;
printf("Total is %d.
",total);
}
if (customers >= 0 && customers < 10){
total = customers*300 ;
printf("Total is %d.
",total);
}
return 0;
}
#include
int main () {
int a;
printf("please enter the number of customers: ");
scanf("%d", &a);
if(a >= 10) {
a = a * 300 * 0.8;
}
if(a < 10) {
a = a * 300;
}
printf("total:%d
", a);
return 0;
}
my attempt
#include
int main()
{
int money=300,person;
printf("please enter customer number:");
scanf("%d",&person);
money=money*person;
if(money>=3000)
{
money=money*0.8;
printf("%d",money);
}
else
{
printf("%d",money);
}
return 0;
}