C programlama dilinde nasıl borsa Simulatorü yapılabilir?

KS
KS
Gullit

Gullit

Femtopat
Katılım
11 Temmuz 2022
Mesajlar
62
Daha fazla  
Cinsiyet
Erkek
Matematik kısmı ve nasıl depolanacağı

Rastgele bir sayı alıp bu sayıya göre %20 artış yapmak veya %10 azalış veya %10 artış gibi ayrı ayrı durumlar yapmak istiyorum bunu nasıl koda dökebilirim?
 
S

Silinen üye 266150

Ziyaretçi
Matematik kısmı ve nasıl depolanacağı

Rastgele bir sayı alıp bu sayıya göre %20 artış yapmak veya %10 azalış veya %10 artış gibi ayrı ayrı durumlar yapmak istiyorum bunu nasıl koda dökebilirim?
Örnek bir betik mesela :
int a; a=a*110/100; printf(a,%f); a=a*80/100;

gibi şekillerde olabilir. Farklı durumlar için değişkenler numaralandırılabilir. A1,A2,A3 gibisinden ve A(Numara) olan kısımlara // ile tarihleri ve saatleri belirtilebilir.
 
KS
KS
Gullit

Gullit

Femtopat
Katılım
11 Temmuz 2022
Mesajlar
62
Daha fazla  
Cinsiyet
Erkek
hayır printf vermiyorum bir while döngüsünün içindeyim ve beni while döngüsünün başına gönderiyor
 
KS
KS
Gullit

Gullit

Femtopat
Katılım
11 Temmuz 2022
Mesajlar
62
Daha fazla  
Cinsiyet
Erkek
While döngüsünün başlangıcına dönünce değerin güncellenmesini istiyorum

C:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <time.h>


int main() {
    
    int choice=0;
    float depo,draw;
    srand(time(NULL));
    
        float money;
        int x,stchoice;
        x = rand() % 1;
        if (x == 2) {
            money = rand() % 200000+50;
        }
        else if (x == 1) {
            money = rand() % 2000 + 500;
        }
        else{
            money =1000; // simdilik 1000 para ile test amacli sonrasında sansa gore para verilecek//
        }

        float a, b, c, d;
        a = 100 + rand() % 10;
        b = 190 + rand() % 8;
        c = 100 + rand() % 10;
        d = 140 + rand() % 5;

        int option;
        int buy,sell;
        float bank=0;
        int sit;
        sit = rand() % 5;
    printf("Welcome to the Cornerstone BANK!(for atm press any key)");
    getchar();

    while (choice != 3) {
    starting:
        printf("What would you like to do?(1=deposit 2=withdraw 3=investment 4=exit from bank)");
        printf("\nYour balance is %.2f$\n", money);
        scanf("%d", &choice);
        if (choice == 1) {
            printf("How many dollars would you like to deposit?\t");
            scanf("%f", &depo);
            money +=depo;
        }
        else if (choice == 2) {
            printf("How many dollars would you like to withdraw?\t");
            scanf("%f", &draw);
            if (draw <= money) {
                money -= draw;
            }
            else
                printf("\aSorry! You cannot afford this!\n");
        }
        else if (choice == 3) {
            printf("Here is some market stock:\nAmazon:%.2f\tTesla:%.2f\tGoogle:%.2f\tBiontech:%.2f\n",a,b,c,d);
            printf("Choose a market stock (1 amazon 2 tesla 3 google 4 biontech,other main menu)");
            scanf("%d",&stchoice);
            if (stchoice == 1) {
                printf("One Amazon stock costs %.2f$ Would you like to buy it or sell it? Buy:1 Sell:2 main menu:3 ", a);
                scanf("%d", &option);
                if (option == 1) {
                    printf("How many stock would you like to buy it?");
                    scanf("%d", &buy);
                    if (a * buy <= money) {
                        bank += a * buy;
                        money -= a * buy;
                        printf("You succesfully bought %d Amazon stock\n", buy);
                    }
                    else {
                        printf("Sorry! You cannot afford this!\n");
                        goto starting;
                    }
                    
                    goto starting;
                }
                else if (option == 2) {
                    printf("How many stock would you like to sell it?");
                    scanf("%d", &sell);
                    
                    if (bank >= sell*a) {
                        printf("You succesfully sold %d Amazon stock\n", sell);
                        bank -= a * sell;
                        money += a * sell;
                    }
                    else {
                        printf("Sorry. You do not have enough stocks for sell number!\n");
                        goto starting;
                    }
                    goto starting;
                    if (sit != 15) {
                        a=a*110/100; //burda kaldım henüz borsadaki artıs azalıslara baglı bir sistem kurulamadı arrayler olabilir amazonun büyük kısmı yapıldı
                }
                }
                else
                {
                    goto starting;
                }
            }
            else if (stchoice == 2) {
                printf("One Tesla stock costs %.2f$ Would you like to buy it?", b);
            }
            else if (stchoice == 3) {
                printf("One Google stock costs %.2f$ Would you like to buy it?", c);
            }
            else if (stchoice == 4) {
                printf("One Biontech stock costs %.2f$ Would you like to buy it?", d);
            }
            else
            {
                goto starting;
            }
        }
        else {
            printf("Thank you for choosing us!");
            break;
        }
    }


    
    return 0;
}

burda fonksiyon kullansam daha kısa olabilirdi fonksiyonları tam kavrayamadım
 
S

Silinen üye 266150

Ziyaretçi
While döngüsünün başlangıcına dönünce değerin güncellenmesini istiyorum

C:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <time.h>


int main() {
   
    int choice=0;
    float depo,draw;
    srand(time(NULL));
   
        float money;
        int x,stchoice;
        x = rand() % 1;
        if (x == 2) {
            money = rand() % 200000+50;
        }
        else if (x == 1) {
            money = rand() % 2000 + 500;
        }
        else{
            money =1000; // simdilik 1000 para ile test amacli sonrasında sansa gore para verilecek//
        }

        float a, b, c, d;
        a = 100 + rand() % 10;
        b = 190 + rand() % 8;
        c = 100 + rand() % 10;
        d = 140 + rand() % 5;

        int option;
        int buy,sell;
        float bank=0;
        int sit;
        sit = rand() % 5;
    printf("Welcome to the Cornerstone BANK!(for atm press any key)");
    getchar();

    while (choice != 3) {
    starting:
        printf("What would you like to do?(1=deposit 2=withdraw 3=investment 4=exit from bank)");
        printf("\nYour balance is %.2f$\n", money);
        scanf("%d", &choice);
        if (choice == 1) {
            printf("How many dollars would you like to deposit?\t");
            scanf("%f", &depo);
            money +=depo;
        }
        else if (choice == 2) {
            printf("How many dollars would you like to withdraw?\t");
            scanf("%f", &draw);
            if (draw <= money) {
                money -= draw;
            }
            else
                printf("\aSorry! You cannot afford this!\n");
        }
        else if (choice == 3) {
            printf("Here is some market stock:\nAmazon:%.2f\tTesla:%.2f\tGoogle:%.2f\tBiontech:%.2f\n",a,b,c,d);
            printf("Choose a market stock (1 amazon 2 tesla 3 google 4 biontech,other main menu)");
            scanf("%d",&stchoice);
            if (stchoice == 1) {
                printf("One Amazon stock costs %.2f$ Would you like to buy it or sell it? Buy:1 Sell:2 main menu:3 ", a);
                scanf("%d", &option);
                if (option == 1) {
                    printf("How many stock would you like to buy it?");
                    scanf("%d", &buy);
                    if (a * buy <= money) {
                        bank += a * buy;
                        money -= a * buy;
                        printf("You succesfully bought %d Amazon stock\n", buy);
                    }
                    else {
                        printf("Sorry! You cannot afford this!\n");
                        goto starting;
                    }
                   
                    goto starting;
                }
                else if (option == 2) {
                    printf("How many stock would you like to sell it?");
                    scanf("%d", &sell);
                   
                    if (bank >= sell*a) {
                        printf("You succesfully sold %d Amazon stock\n", sell);
                        bank -= a * sell;
                        money += a * sell;
                    }
                    else {
                        printf("Sorry. You do not have enough stocks for sell number!\n");
                        goto starting;
                    }
                    goto starting;
                    if (sit != 15) {
                        a=a*110/100; //burda kaldım henüz borsadaki artıs azalıslara baglı bir sistem kurulamadı arrayler olabilir amazonun büyük kısmı yapıldı
                }
                }
                else
                {
                    goto starting;
                }
            }
            else if (stchoice == 2) {
                printf("One Tesla stock costs %.2f$ Would you like to buy it?", b);
            }
            else if (stchoice == 3) {
                printf("One Google stock costs %.2f$ Would you like to buy it?", c);
            }
            else if (stchoice == 4) {
                printf("One Biontech stock costs %.2f$ Would you like to buy it?", d);
            }
            else
            {
                goto starting;
            }
        }
        else {
            printf("Thank you for choosing us!");
            break;
        }
    }


   
    return 0;
}

burda fonksiyon kullansam daha kısa olabilirdi fonksiyonları tam kavrayamadım
Bende tam onu söyleyecektim. Düzeltmekle uğraşabilirim ama sıfırdan yazsam daha kısa sürebilir bile 😁😁

Akşam bir üzerinde çalışacağım hocam sorununuzun.
 

Yeni konular

Yukarı