Point Out Mistake!!!

This is a discussion on Point Out Mistake!!! within the C Programming forums, part of the General Programming Boards category; I m learner . this is my 3 rd programming ..plz help me.. I wrote this programme today but at ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    83

    Thumbs up Point Out Mistake!!!

    I m learner . this is my 3 rd programming ..plz help me..
    I wrote this programme today but at last while i m compling than there is no problem but when runnung it give me option to ignore , skip all odds some thing like this , plz point the mistake..

    And if some body has turbo c 3.00 plz provide me that...


    Code:
    #include<stdio.h>
    main()
    {
    int a,b,c;
    float x,d;
    printf("Enter the Numbers a,b,c,d);
    scanf("%d %d %d %f" , &a,&b,&c,&d0;
    
    x=a*b+c*d;
    
    printf("%f" , x);
    
    getchar();  
    }
    Can i write down the program in Bold here?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,822
    Well you could start by posting the code you actually compiled, rather than the random stuff you thought you had which doesn't compile.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    83
    i have complied it....

  4. #4
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    with what compiler?

    and why do you want turbo c 3?

    bloodshed and microsoft both have a free to use IDE that work well and output error messages as to whats wrong with your code. you can download the IDE produced by bloodshed from here: http://prdownloads.sourceforge.net/d....9.2_setup.exe or from microsoft here: http://msdn.microsoft.com/vstudio/ex...ualc/download/
    Registered Linux User #380033. Be counted: http://counter.li.org

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,822
    > i have complied it....
    Well your compiler is crap.

    printf("Enter the Numbers a,b,c,d);
    This is missing a "

    scanf("%d %d %d %f" , &a,&b,&c,&d0;
    You forgot to hold down the shift key to make that 0 a )
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User
    Join Date
    Apr 2006
    Posts
    83
    i think my compiler is really crap ....even i i can't select the text ,i typed...

    i m trying the given link now

  7. #7
    Registered User
    Join Date
    Apr 2006
    Posts
    83
    i just installed the compiler u said. thnx pal
    I think this compiler will solve my 40 % problem and rest 40% will be solved by u all..

    I will solve 20 % of my self...

    Thanks Pal for the compiler i will be back soon with problems..

  8. #8
    Registered User
    Join Date
    Apr 2006
    Posts
    83

    Red face

    Now This code has no errors.....it also runs and according to the programing ...it asks for input "enter basic salary"
    as i put the value....run window get closed everytime help me friends...

    Code:
    #include<stdio.h>
    int main()
    {
          float bs,gs,da,hra;
          
          
          
          printf("enter basic salary");
         scanf("%f",&bs);
          
          if(bs<1500)
          {
                     hra=bs*10/100;
                     da=bs*90/100;
                     }
                     else
                     {
                         hra=500;
                         da=bs*98/100;
                         }
                     
          gs=bs+hra+da;
          printf("Gross Salary=Rs%f",gs);
          getchar();           
             
    }

  9. #9
    Registered User
    Join Date
    Jan 2006
    Location
    Berkeley, Ca
    Posts
    195
    Code:
    int main()
    should be
    Code:
    int main(void)
    Code:
     printf("enter basic salary");
    should be
    Code:
     printf("enter basic salary\n");
    Notice I put in '\n'. Under ANSI C, failing to include '\n' in the printf() function could lead to undefined behavior.

    Code:
    scanf("%f",&bs);
    This should be re-written like:
    Code:
    if ( scanf("%f",&bs) ==1)
    scanf() blows. But if you must use it, check for the return value. In this case, when when I check for the return value, the function would discard input like letters after the numbers. It's not perfect, but it's sort of respectable.

    Okay, the hangover is getting worse. At the end of your program, put in the line of code
    Code:
    return 0;
    As for the windows closing, I do believe this is an Operating Specific/compiler Specific Issue. Check your compiler to see if there is some kind of option to keep the window open after the program executes.
    Last edited by cdalten; 04-22-2006 at 05:51 PM.

  10. #10
    Registered User
    Join Date
    Apr 2006
    Posts
    83
    Thnx Pal... A shake Hand From me ,For u..... Thanks Again

  11. #11
    Registered User 00Sven's Avatar
    Join Date
    Feb 2006
    Posts
    127
    For the window closing it depends on the Operating System. What OS are you on?
    ~Sven
    Windows XP Home Edition - Dev-C++ 4.9.9.2
    Quote Originally Posted by "The C Programming Language" by Brian W. Kernignhan and Dennis M. Ritchie
    int fflush(FILE *stream)
    On an output stream, fflush causes any buffered but unwritten data to be written; On an input stream, the effect is undefined. It returns EOF for a write error, and zero otherwise. fflush(NULL) flushes all output streams.
    board.theprogrammingsite.com

  12. #12
    Registered User
    Join Date
    Jan 2006
    Location
    Berkeley, Ca
    Posts
    195
    Okay, I just want to elaborate a little on why you should always have something like

    Code:
    return 0;
    at the end of main().
    C is a general programming language. This means it tends to muck together a lot of computer science concepts. Moving along...Having a return value at the end of main() is a property of a function. Some other languages will also use procedures. This is a different beast. The main thing to understand is that C has functions and functions return a value. This is something you should keep in the back of your head when you start doing more coding.

  13. #13
    Registered User 00Sven's Avatar
    Join Date
    Feb 2006
    Posts
    127
    Main can also return other things. Whatever it returns it returns to the operating system. 0 usually signals success. So saying
    Code:
    return 0;
    tells your operating system that your program successfully ended.

    To make your program stay on the screen...
    You can use getchar() to pause and wait for the user to press enter. You do not need to assign this to anything. Just add a line at the end of the program that is
    Code:
    getchar();
    Or if using Dev-C++ (which I think you are) you can use getch() This is defined in stdio at least in Dev-C++. It does not display any text that you type in but it does pause your program until the user hits any key. The key does not need to be enter it can be anything. Like getchar() You just add a line at the end of your program that is
    Code:
    getch();
    No arguments or assignments, just the funtion. Hope this helps.
    ~Sven
    Windows XP Home Edition - Dev-C++ 4.9.9.2
    Quote Originally Posted by "The C Programming Language" by Brian W. Kernignhan and Dennis M. Ritchie
    int fflush(FILE *stream)
    On an output stream, fflush causes any buffered but unwritten data to be written; On an input stream, the effect is undefined. It returns EOF for a write error, and zero otherwise. fflush(NULL) flushes all output streams.
    board.theprogrammingsite.com

  14. #14
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    I wouldn't recommend getch(), it's not a standard function. You could printf() "Press enter to quit" and add a getchar() on the end. You could say "press enter to continue" and add this anywhere in your program, really.

    The program is a commandline program, and was made to run from the command line. Thus the immediate exit.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  15. #15
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Drawing Program
    By Max_Payne in forum C++ Programming
    Replies: 21
    Last Post: 12-21-2007, 05:34 PM
  2. Classes & Collections
    By Max_Payne in forum C++ Programming
    Replies: 7
    Last Post: 12-11-2007, 01:06 PM
  3. Why not use an = Operator instead of a Copy Constructor?
    By thetinman in forum C++ Programming
    Replies: 48
    Last Post: 10-15-2007, 04:58 PM
  4. How to decide if four lines form a square?
    By Koedoe in forum C++ Programming
    Replies: 6
    Last Post: 10-01-2002, 11:38 AM
  5. point lies in circle?
    By cozman in forum Game Programming
    Replies: 3
    Last Post: 12-20-2001, 04:39 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21