Çözüldü C ile adisyon sistemi yapma

Bu konu çözüldü olarak işaretlenmiştir. Çözülmediğini düşünüyorsanız konuyu rapor edebilirsiniz.

Cyberilia

Kilopat
Katılım
10 Mayıs 2017
Mesajlar
266
Makaleler
5
Çözümler
1
Yer
Ankara İncek
Daha fazla  
Cinsiyet
Erkek
Meslek
Atılım Universitesi Yazılım Muhendisliği
C:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
    int i, order, o;
    double total;
    char split;
    i=1;
    total=0.0;
    printf("Welcome! How many drinks will be ordered?\n");
    scanf("%d",&order);
    printf("\nMENU: \n1. Espresso \n2. Latte \n3. Cappuccino \n4. Tea\n");
    while(i<=order)
    {

        scanf("%d",&o);
        switch(o)
        {
            case 1:
                printf("You have ordered one Espresso, which costs 4.5$\n");
                total=total+4.5;
                break;
                case 2:
                    printf("You have ordered one Latte, which costs 5.5$\n");
                    total=total+5.5;
                    break;
                    case 3:
                        printf("You have ordered one Cappuccino, which costs 6.5$\n");
                        total=total+6.5;
                        break;
                        case 4:
                            printf("You have ordered one Tea, which costs 3.5$\n");
                            total=total+3.5;
                            break;          
        }
    i=i+1;
    }
    printf("Would you like to split the bill between 3 guests?\n");
    scanf("%c",&split);
    switch(split)
    {
        case 'y':
            case 'Y':
                total=total/order;
                printf("The amount that each guest needs to pay is %2.1f$",total);
                break;
                case 'n':
                    case 'N':
                        printf("The total amount that you need to pay is: %2.1f$\n",total);
                        break;
               
}
   


    return(0);  
}
Kod bu while bittikten sonra printf ile Would you like to split the bill between 3 guests? sorusu gelip cevap alınması gerekiyor fakat while bittikten sonra printleyip input girmeme izin vermeden direk bitiyor.
Benim run
"
Welcome! How many drinks will be ordered?
3

MENU:
1. Espresso
2. Latte
3. Cappuccino
4. Tea
1
You have ordered one Espresso, which costs 4.5$
2
You have ordered one Latte, which costs 5.5$
4
You have ordered one Tea, which costs 3.5$
Would you like to split the bill between 3 guests?

--------------------------------
Process exited after 5.111 seconds with return value 0
Press any key to continue . . .
"

Olması gereken ise bu:

"Welcome! How many drinks will be ordered? 3
MENU: 1. Espresso 2. Latte 3. Cappuccino 4. Tea
1
You have ordered one Espresso, which costs 4.5$
2
You have ordered one Latte, which costs 5.5$
4
You have ordered one Tea, which costs 3.5$
Would you like to split the bill between 3 guests?
Y
The amount that each guest needs to pay is 4.50$"


Neyi yanlış yaptım acaba?
 
Son düzenleyen: Moderatör:
Çözüm
scanf fonksiyonlarının hepsinde % işaretinden önce bir boşluk bırak sorun çözülür. " %d" şeklinde..
scanf fonksiyonlarının hepsinde % işaretinden önce bir boşluk bırak sorun çözülür. " %d" şeklinde..
Teşekkür ederim işe yaradı fakat boşluk tam olarak ne işe yarıyor 11.satırdaki scanfde de boşluk kullanmadım fakat onda sıkıntı çıkarmıyor.
 
Boşluk bırakarak son whitespace karakterlerinden itibaren okumasını sağlıyoruz böylece önceki satırdan kalan artıklar input'a dahil olmayıp scanf fonksiyonunun yanlış girdi almasını engelliyor.
Teşekkür ederim.
 

Geri
Yukarı