Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 C++ Output
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Hugetanks




PostPosted: Fri May 17, 2019 8:23 pm   Post subject: C++ Output

Hello, I just started learning C++ for competitive programming, and I'm confused with what my output gives me. Can someone tell me what's wrong with my code?

c++:
#include <iostream>

int main()
{
    int longer, counter = 0;
    char dummy;
    std::cin>>longer;
    char num[80];
   
    for (int i = 0; i < longer; i++)
    {
        std::cin.getline(num,80);
        dummy = num[0];
        for (int k = 0; k < sizeof(num)/sizeof(num[i]); k++)
        {
            if (num[k] == dummy)
                counter++;
            else
            {
                std::cout << counter << " " << dummy << " ";
                dummy = num[k];
                counter = 0;
            }
        }
        std::cout<<"\n";
    }
       
    return 0;
}


It's for this question: https://dmoj.ca/problem/ccc19j3 Thanks![/syntax]
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: