folder Tahribat.com Forumları
linefolder C - C++
linefolder C++ Cin.Get(Ch) Yardımı



C++ Cin.Get(Ch) Yardımı

  1. KısayolKısayol reportŞikayet pmÖzel Mesaj
    solstice
    solstice's avatar
    Kayıt Tarihi: 04/Nisan/2008
    Erkek

    ------------------input a girilicek değerler--------------------

    234

    ali toprak

    45 56 78 34 12  -999

    235

    ayşe uzun

    34 12 34 56 78 90 34 -999

    236

    osman büyük

    12 34 78 43 54 23 78 90 23 -999

    237

    leman tas

    21 34 56 78 98 32 -999

    238

    (çıktısı aşağıdaki gibi olcak)

    ID

    Name

    Votes

    şeklinde çıktı olcak

    *-------------------------

    not : the number -999 acts as a sentianel. student council's candidates are given as in the following form :

    ID

    Name

    Votes

    şeklinde sıra oluşacak.

    arkadaslar sorudan pek bişi anlamadım ama

    soruda satırları

    char ch;

    cin.get(ch) tanımlayarak satırları atlatıcaz. id ler isimlerin başına geçicek. ve burda while içinde while kullanmam gerekiyormuş.

    birde elimde şöyle bir kod var :

    #include <iostream>
    #include <cmath>
    #include <string>
    using namespace std;
    int main()
    {
    int sum;
    int vote;
    string name;
    getline(cin, name);
    while(cin)
    {
    cout<<name<<" ";
    sum=0;
    cin>>vote;
    while(vote != -999)
    {
    sum=sum+vote;
    cin>>vote;
    }
    cout<< "sum ="<<sum;
    cin>>name;
    }
    return 0;
    }

    buna cin.get(ch) ı eklesek satır ve id sorununu nasıl halledebiliriz ?

     

     

     

     

     


    https://www.youtube.com/watch?v=k6LrGZGqYn8
  2. KısayolKısayol reportŞikayet pmÖzel Mesaj
    solstice
    solstice's avatar
    Kayıt Tarihi: 04/Nisan/2008
    Erkek

    #include
    #include
    using namespace std;
    int main()
    {
    string name;
    int id,vote,sum;
    char ch;
     
    cin>>id;//getline(cin,id);
    while (cin)//id!=-1
    {
    cin.get(ch);
    getline(cin,name);
    cin>>vote;
    sum=0;
    while (vote!=-999)
    {
    sum=sum+vote;
    cin>>vote;
    }
    cout<<"id="<<<"sum="<<
    cin>>id; //cin>>id;
    }
    return 0;
    }

     

    sorun çözüldü.


    https://www.youtube.com/watch?v=k6LrGZGqYn8
Toplam Hit: 1458 Toplam Mesaj: 2