Should I leave out the semicolons in 'if' statements? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Should I leave out the semicolons in 'if' statements?

Dont forget to answer to my subject line.


What if I wanted to make the user type in a yes or no answer to a question, how do I do that? my example:


yes=0;

no=0; /*you could tell that these or no variables, I cant find a single way of asking the user a question with 'yes' or 'no'


How do I make buttons in C, like you can do in Visula Basic?

Like pressing? Yes and No?


I like that C is the best computer language to start with, because in Visual Basic there is not much coding going on, and everything is mostly done with following instructions, and making graphical stuff on the screen rather than C, just coding on a piece of paper.

Rather that I dont know what Visual Basic code looks like, but I will stick with C.



Thanks




Comments

  • : Dont forget to answer to my subject line.




    How about a 'please'? I'm doing this on my own time after all.


    The 'if construct' doesn't have a semicolon following it. The statement that gets executed in the event of the condition being true must have a semicolon following it just like any other statement in C (unless the code to execute is actually a block of statements, wrapped in curly braces, in which case no semicolon is appended).


    For example:


    int a=3,b;

    b=2;


    if (a>b)

    cout << "a is greater than b" << endl;<p>
    a=5;


    if (a>b)

    {

    cout << "a is still greater than b" << endl;<br>
    cout << "so there." << endl;<br>
    }

    else

    cout << "a is now less than b" << endl;<p>



    : What if I wanted to make the user type in a yes or no answer to a question, how do I do that? my example:


    : yes=0;

    : no=0; /*you could tell that these or no variables, I cant find a single way of asking the user a question with 'yes' or 'no'




    Well, I presume yes and no have been declared somewhere as numbers that you're not showing me. The assigment's fine then.


    If you want to ask the user a question and have them respond with 'yes' or 'no', I suggest reading in a string into a character buffer (array) of sufficient size and then testing the user's input with strcmp.





    : How do I make buttons in C, like you can do in Visula Basic?




    You don't want to go there. If you're just learning C, interacting with an operating system's GUI is just way hideous to jump into. It's different for every operating system, and there's a lot of hoops to jump through.




    : Like pressing? Yes and No?


    : I like that C is the best computer language to start with, because in Visual Basic there is not much coding going on, and everything is mostly done with following instructions, and making graphical stuff on the screen rather than C, just coding on a piece of paper.




    Visual basic is a heck of a lot easier to design graphical user interfaces with. I haven't even coded a great deal in Visual basic and I know that.


    I don't understand what distinction you're trying to make, particularly. C is nothing more than 'following instructions' when you get down to it. In fact, you have to typically specify more instructions in C than in Visual Basic to do a lot of the user interface nicities.




    : Rather that I dont know what Visual Basic code looks like, but I will stick with C.




    Most computer languages share similarities. When I write a program, for example, to solve some sort of problem, I try not to think of it in a particular language. I try to solve it algorithmically... sort of lay out a 'way to do it'. Then I figure out how to make a particular language, like C, actually do it.


    But if you're sticking with C, good for you. I just suggest you don't try to jump into GUI work until you're relatively familiar with the language. Interacting with the operating system like that is more complicated, not less.



    : Thanks





Sign In or Register to comment.