Please Help- my first program does something weird ! - Page 2
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 28 of 28

Thread: Please Help- my first program does something weird !

  1. #16
    Join Date
    Apr 1999
    Posts
    27,444

    Re: Please Help- my first program does something weird !

    Quote Originally Posted by Jeff++ View Post
    ok thank... but the g++ part went right over my head.

    where does the g++ come from ? and the switch names ?

    thanks.
    When you installed Dev-C++, it also installed the g++ (mingw) compiler. Look at the directories where it was installed. Also, those switches are probably set in the project options, but I don't have Dev-C++ in front of me to tell you exactly where to set them.

    You need to do this, since otherwise you will inadvertantly create invalid C++ programs (so many posters using g++ make this same error of not setting the appropriate compiler switches beforehand).

    Regards,

    Paul McKenzie

  2. #17
    Join Date
    Feb 2009
    Posts
    80

    Re: Please Help- my first program does something weird !

    is it important to put

    int r=0;

    as opposed to just

    int r;

    ??

    it's always 0 if not defined right ?
    so why bother if it gets a digit assigned to it later in the code ?

    thanks

  3. #18
    Join Date
    Feb 2009
    Posts
    80

    Re: Please Help- my first program does something weird !

    so Paul... I hear what you're saying, sort of. In other words without adding the switch name....
    I'm using a different compiler than I should be ?
    the switch name is instructions to use compiler g++ instead ?

    if this is so, why does it not mention it anywhere in the included instructions or tutorials ?

    cheers.

  4. #19
    Join Date
    Feb 2009
    Posts
    80

    Re: Please Help- my first program does something weird !

    I'm seeing so many differences in what you folks are saying and my tutorial I've been reading...
    like...
    the tutorial has taught me the use of printf and scanf
    but everyone seems to be using cout and cin,
    yet this tutorial makes no mention of cout and cin.

    can someone tell me the difference between them PLEASE.....
    which one should I use ? where ? why ?

    or better yet
    maybe direct me to a better tutorial for total newbies.
    so I can start over.

    cheers.

  5. #20
    Join Date
    Feb 2009
    Posts
    80

    Re: Please Help- my first program does something weird !

    maybe first I should ask if I'm using the right language.

    I want to one day be making video games.

    I heard C++ was great for that so that's why I chose it as my first language here...
    but what is
    Visual C++ ? is that better ?

    thanks.

  6. #21
    Join Date
    Apr 1999
    Posts
    27,444

    Re: Please Help- my first program does something weird !

    Quote Originally Posted by Jeff++ View Post
    I'm using a different compiler than I should be ?
    the switch name is instructions to use compiler g++ instead ?
    You don't need to use g++ directly -- the DevC++ environment does this for you.

    If you go to the Project and Project Settings, there should be an option to set the compiler parameters. Those parameters are the ones I mentioned:

    -pedantic -Wall

    You can test if you've set the switches correctly by compiling the following:
    Code:
    int main()
    {
        int num = 10;
        int array[num];
    }
    If this code doesn't compile and gives you an error where the array is declared, you have set the switches correctly. If it does compile successfully, then you still have the extensions turned on and you need to try something else to turn them off.
    if this is so, why does it not mention it anywhere in the included instructions or tutorials ?
    DevC++ only has instructions on how to use DevC++, not the g++ compiler it runs underneath the hood. For that, you need to go to the Gnu website or mingw website.

    Regards,

    Paul McKenzie

  7. #22
    Join Date
    Feb 2009
    Posts
    80

    Re: Please Help- my first program does something weird !

    well thanks Paul, but when I click " Project Options " I get an error. Obviously a bug, it does it every time.
    I get this

    Application version: 4.9.9.2

    Machine info
    ---------
    Platform : Windows NT
    OS version : version 6.0 (build 6001)
    Additional info: Service Pack 1


    The following error occured in version 4.9.9.2:
    Access violation at address 0012F647. Write of address 0012F647 (at address 0x0012F647)


    Please include a description of what you were doing before the error occured (please give as much precisions as possible) :


    State information follows:
    Stack trace:
    ------------
    0058F80A (0018E80A): ShowExceptionInfo (ExceptionsAnalyzer - 566)
    0058F9FF (0018E9FF): TExceptionsAnalyzer.GlobalExceptionHandler (ExceptionsAnalyzer - 574)
    005712FA (001702FA): TfrmProjectOptions.InitVersionInfo (ProjectOptionsFrm - 1026)
    0056EC8F (0016DC8F): TfrmProjectOptions.SetOptions (ProjectOptionsFrm - 513)
    00578C83 (00177C83): TProject.ShowOptions (project - 1674)
    00559E2E (00158E2E): TMainForm.actProjectOptionsExecute (main - 3551)
    0059105B (0019005B): (devcpp - 230)
    00591079 (00190079): (devcpp - 230)





    Which I'm assuming means " screw you buddy, I'm a computer program... I don't need to work right"

    guess I'll have to see if there's a bug fix before I can change those settings.
    thanks though.

    any insight on my other questions would be great.

    1. what is the difference between " cin, cout " and " printf, scanf " ? should I use one over the other ?

    2. What's the dif between C++ and Visual C++ ? I want to make video games in the future...
    should I be using visual ?

    3. can someone direct me to a more up to date tutorial for total newbies ?
    one that explains cout and cin better.

    THANK YOU ALL !!

  8. #23
    Join Date
    Apr 1999
    Posts
    27,444

    Re: Please Help- my first program does something weird !

    Quote Originally Posted by Jeff++ View Post
    well thanks Paul, but when I click " Project Options " I get an error. Obviously a bug, it does it every time.
    I get this

    Application version: 4.9.9.2
    I would suggest getting the CodeBlocks IDE for g++. It is currently maintained, while Dev C++ is basically a dead project.
    1. what is the difference between " cin, cout " and " printf, scanf " ? should I use one over the other ?...
    3. can someone direct me to a more up to date tutorial for total newbies ?
    one that explains cout and cin better.
    A good C++ book describes the difference between cin and cout. If you don't have a good C++ book, you need to get one since C++ isn't something you can learn "on the fly" or winging it. It just doesn't work that way. As to websites, many, if not most are notorious for giving wrong, outdated, or bad information concerning C++ programming. Unless the website has been recommended by C++ industry professionals, don't learn from them.

    One site that is very good is this:

    www.parashift.com

    On the other hand, books are peer-reviewed, so any wrong information is usually corrected before publication (not all C++ books, but most) -- the same cannot be said about C++ websites.
    2. What's the dif between C++ and Visual C++ ?
    C++ is a computer language invented by Bjarne Stroustrup and officially specified by ANSI/ISO in the year 1998.

    Visual C++ is a brand of compiler created by Microsoft that compiles C++ code.

    Regards,

    Paul McKenzie

  9. #24
    Join Date
    Feb 2009
    Posts
    80

    Re: Please Help- my first program does something weird !

    hey thanks again paul.
    I think you misunderstood me about the cin , cout thing.
    I understand there use fine...
    what I meant was, why use printf vs. cout ? is one better in certain situations ?

    PS- I just use Dev C++ because I wanted to learn and I found it for free on the net.

    cheers.

  10. #25
    Join Date
    May 2007
    Location
    Scotland
    Posts
    1,145

    Re: Please Help- my first program does something weird !

    Quote Originally Posted by Jeff++ View Post
    ok,
    I see, you left off the other part. If I combine that with what I had at the end I get

    Code:
    #include <stdio.h>
    #include <conio.h>
    
    int main()
    {
      int r=0;
    
      do
      {
        int c=0;
        while(c <=9){
        printf("Print 10 !\n\n");
        ++c;
        }
        printf("want to re-print ? then you need to find the lucky number !\n\n if you get it wrong you will have to quit !");
        scanf("%d",&r);
      }
      while(r==4);
    
    
     
    {       printf("click any key to quit");
            
    }                                                     
    getche();
    
    }
    which seems to work just fine.

    is this considered good syntax now ?

    cheers.
    It's ok, but you don't need to restrict the scope of your "click any key to quit" statement. i.e.

    Code:
    {
      printf("click any key to quit");
    }
    can become simply
    Code:
    printf("click any key to quit");
    With regards to printf/scanf and cout/cin, it depends on the language in which you are writing. Your program is a C program, it includes C headers (e.g. #include<stdio.h>) and uses C IO functions (printf, scanf). A C++ program includes C++ headers (e.g. #include<iostream>) and consequently will use C++ IO objects (cout, cin).

    Although you can use the C printf and scanf functions in C++, they are not typesafe and this is a problem when writing C++ programs where you may want to stream non-POD (Plain Old Data) types such as classes.

    The program you have written is clearly a C program. An equivalent C++ program would be

    Code:
    #include <iostream>
    
    int main()
    {
      int r=0;
    
      do
      {
        int c=0;
        while(c <=9){
          std::cout << "Print 10 !\n\n";
        ++c;
        }
        std::cout << "want to re-print ? then you need to find the lucky number !\n\n if you get it wrong you will have to quit !" << std::endl;
    
        std::cin >> r;
        std::cin.clear();
      }
      while(r==4);
    
      system("PAUSE");
    
    }

  11. #26
    Join Date
    Feb 2009
    Posts
    80

    Re: Please Help- my first program does something weird !

    ok, got code blocks downloading now.
    using the intaller package, because I wouldn't know what to do with the source code.

    unless I could put it in Dev C++ and compile it.

    what's the advantage of building the application yourself ?

    thanks

  12. #27
    Join Date
    Apr 1999
    Posts
    27,444

    Re: Please Help- my first program does something weird !

    Quote Originally Posted by Jeff++ View Post
    PS- I just use Dev C++ because I wanted to learn and I found it for free on the net.
    CodeBlocks is also free and currently maintained. DevC++ is a dead project that hasn't been updated in years.

    Regards,

    Paul McKenzie

  13. #28
    Join Date
    Feb 2009
    Posts
    80

    Re: Please Help- my first program does something weird !

    big download and my internet is sloooooow today. I get it free so I can't complain.
    guess I'll leave it downloading and head off to bed soon.

    One last question since you've been the biggest help with this stuff, and I do appreciate it...

    I want to design a C++ program that will open windows calculator at a point in the code...
    and then close it again later in the code.

    I can't seem to find any real answers on this subject anywhere.

    I would think there's some simple code in this language that can open and close exe files,
    can you give me an example how to do that ?

    thanks again so much for your time.
    cheers

Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center