Thread: hekp with programming

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    OK, so I see a lot of problem here.
    First, madscientist posted in the C++ section (not C!), and specifically asked for help in C++ (not C!).
    Secondly, cauberong09 dumped a solution to a problem directly (which is discouraged), which has a lot of defects (for example, undefined behavior), and finally posted code in C (not C++!).

    So let's clear this up now.
    Is this supposed to be C or C++?
    C does not belong in the C++ forum and vice versa. Therefore, it is strongly discouraged to post examples or code in C in the C++ forum or vice versa. If this is indeed supposed to be C++, then cauberong09's code does not belong here, nor should it have been posted in the first place.
    If this is indeed C, then this post is in the wrong forum.

    Also, cauberong09. It is understandable that you want to learn more, and that is fine. I would recommend that you actually read people's problems and the answers to them instead of dumping code. You will learn a lot. I guarantee it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Registered User
    Join Date
    Jan 2012
    Posts
    5
    it is supposed to be c++..
    so i got a little work done myself and i got this code which does not work right now and i can't find the problem... it compiles without errors but when i run it number of consonants or "integer count" turns out to be zero.. could the problem be fact that im using croatian letters?

    Code:
    #include <stdio.h>
    #include <conio.h>
    #include <ctype.h>
    #include<stdlib.h>
    int main()
    {
        system("cls");
        int count=0;
        char ce;
        printf("Enter a charracter:");
        do
        {
            ce=getche();
             char t = tolower(ce);
            if (t == 'q' && t == 'w' && t == 'r' && t == 'z' && t == 'p' && t == 'š' && t == 'đ'
            && t == 's' && t == 'd' && t == 'f' && t == 'g' && t == 'h' && t == 't'
            && t == 'j' && t == 'k' && t == 'l' && t == 'č' && t == 'ć' && t == 'ž' 
            &&t == 'y' && t == 'x' && t == 'c' && t == 'v' && t == 'b' && t == 'n' && t == 'm')
                count++;
        }
        while (ce!='a');
        
        printf("\nNumber of consonants:%d",count);
        getche();
        system("pause");
    }
    i went with this because the last program that worked with condition " if (t!='a'&&t!='u'&&t!='i'&&t!='o'&&t!='e')" counted "space" and "enter" keys as consonants...

  3. #18
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    You need to brush up on your boolean logic.

    > t == 'q' && t == 'w'
    If t is 'q', then it won't be 'w' will it?

    Perhaps try it with || rather than &&
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #19
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    it is supposed to be c++..
    Just so you know, it's really not; there is not a single line of that that's actually C++; it's all vanilla C (with the exception of the antiquated conio.h header thrown in there just so you can avoid running this from the command line as it should be, or configuring your IDE to not close console windows when debugging).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 12-11-2011, 04:25 PM
  2. Simple Median hekp
    By nick753 in forum C++ Programming
    Replies: 6
    Last Post: 10-17-2010, 02:06 PM
  3. small programming job VCPP / Object Oriented Programming
    By calgonite in forum Projects and Job Recruitment
    Replies: 10
    Last Post: 01-04-2006, 11:48 PM
  4. Total newb to programming here... Question about the many programming languages. Ty!
    By tsubotakid1 in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 10-05-2003, 10:32 AM