help plz

This is a discussion on help plz within the C Programming forums, part of the General Programming Boards category; hi i m new 2 the whole C++ n i think its lods of fun i'vebeen puttin a program 2gether...but ...

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    36

    help plz

    hi i m new 2 the whole C++ n i think its lods of fun i'vebeen puttin a program 2gether...but 4 some reason it always seems 2 crash when askin 4 the person status( married etc..)


    the program has been written in french....but i doubt any1 is interested in wat is written with scanf

    i would like 2 thank u all in advance 4 ur time n help
    Code:
    #include <stdio.h>
    
    int main(void)
    {
        int nblivre, c;   
        float kg, cels, frnht;
        
        printf("Taper le poids en livres:\n");
        scanf("%d", &nblivre);
        
        printf("Taper la temperture en degres farenheit:\n");
        scanf("%f", &frnht);
        
        
        
        cels = ((frnht - 32) / 9) * 5;
        kg = 0.454 * nblivre;    
        
        printf("\nLe patient pese %.1f kg, a une temperature de %.1f degres", kg, cels);
         fflush(stdin);
        getchar();
    
        printf("Selectionnez votre status civile:");
         fflush(stdin);
        getchar();
    
         printf("\n\nAffichage avec switch (suivant que) :\n");
        
        
        switch (c)
        {
                        case 'c':
                             printf("celibataire.");
                             break;
                        case 'C': 
                             printf("celibataire.");
                             break;  
                        case 'a':
                             printf("un autre cas.");
                             break;
                        case 'A':
                             printf("un autre cas.");
                             break;
                        case 'm':
                             printf("marie.");
                             break;
                        case 'M':
                             printf("marie.");
                             break;
                        case 'd':
                             printf("divorce.");
                             break;
                        case 'D':   
                             printf("divorce."); 
                             break;
      
      printf("\n");
        fflush(stdin);
        getchar();
        return 0;   
    }
    }

  2. #2
    Registered User
    Join Date
    Oct 2007
    Posts
    36
    i believe my problem is located around the switch level, n i dont know how 2 use it 2 well, that is IF i used it well....tks 4 every1;s help

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,454
    it should be in C not C++ forum

    fflush(stdin); - do not use it - see faq

    switch (c) - is it initialized somewhere? I do not see
    This code
    Code:
                        case 'd':
                             printf("divorce.");
                             break;
                        case 'D':   
                             printf("divorce."); 
                             break;
    Could be shortend to
    Code:
                        case 'd':
                        case 'D':   
                             printf("divorce."); 
                             break;
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379
    As far as I can tell, the variable c is never assigned a value. That may or may not be your problem.

    [Edit]
    Beaten to it ;p
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

  5. #5
    Registered User
    Join Date
    Oct 2007
    Posts
    36
    oh do i assign it ? do i use

    const c

    or


    c = getche()
    ?

  6. #6
    Registered User
    Join Date
    Oct 2007
    Posts
    36
    c is the status which is >>>>a,A,m,M,d,D,C,c

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    1) Do not use netspeak on this forum. Form proper English sentences and write out all the words.
    2) In the future, use descriptive thread titles. "help plz" tells us nothing - most people who create a thread need help.
    3) vart is right, this is straight C. I've moved the thread.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  8. #8
    Registered User
    Join Date
    Oct 2007
    Posts
    36
    ok perfect will do and i m very sorry about that,

    so can someone tell me why my dos page keeps closing down? i have made the necessary changes,

    Code:
    
    #include <stdio.h>
    
    int main(void)
    {
        int nblivre, c;   
        float kg, cels, frnht;
        
        printf("Taper le poids en livres:\n");
        scanf("&#37;d", &nblivre);
        
        printf("Taper la temperture en degres farenheit:\n");
        scanf("%f", &frnht);
        
      
        cels = ((frnht - 32) / 9) * 5;
        kg = 0.454 * nblivre;    
        
         printf("\nLe patient pese %.1f kg, a une temperature de %.1f degres", kg, cels);
         fflush(stdin);
        getchar();
        
        
          printf("Rentrer le statut civil:\n");
        c = getchar();
        switch (c)
        {
                        case 'c':
                        case 'C': 
                             printf("celibataire.");
                             break;  
                        case 'a':
                        case 'A':
                             printf("un autre cas.");
                             break;
                        case 'm':
                        case 'M':
                             printf("marie.");
                             break;
                        case 'd':
                        case 'D':   
                             printf("divorce."); 
                             break;
                             
      printf("\n");
        fflush(stdin);
        getchar();
        return 0;   
    }
    }

    thanks alot for every1's help in advance

  9. #9
    Registered User
    Join Date
    Oct 2007
    Posts
    36
    and what can i use instead of
    Code:
    fflush(stdin)

    being very new i dont know what i can replace it by

  10. #10
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    You can use a proper IDE like Code::Blocks or Visual C++ and run the program (not debug it) - the IDE will keep the console open.

    Then get rid of both the fflush and the getchar.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  11. #11
    Registered User
    Join Date
    Oct 2007
    Posts
    36
    i have 2 use dev-C++

    and i will get ride of the fflush and getchar

  12. #12
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Don't post the same thing twice either, it's a waste of time. Since I answered your questions in the other thread...

  13. #13
    Registered User
    Join Date
    Oct 2007
    Posts
    36
    i didnt....it was moved......from C++ 2 here...zacs7 my dos keep closing be4 it finishes exeecuting everything......and i dont seem 2 understand why


    it crashes @ the switch(c)

  14. #14
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    post your latest code

  15. #15
    Registered User
    Join Date
    Oct 2007
    Posts
    36
    ok so far this is the code
    Code:
    #include <stdio.h>
    
    int main(void)
    {
        int nblivre, c;   
        float kg, cels, frnht;
        
        printf("Taper le poids en livres:\n");
        scanf("%d", &nblivre);
        
        printf("Taper la temperture en degres farenheit:\n");
        scanf("%f", &frnht);
        
        
        
        cels = ((frnht - 32) / 9) * 5;
        kg = 0.454 * nblivre;    
        
        printf("\nLe patient pese %.1f kg, a une temperature de %.1f degres", kg, cels);
         fflush(stdin);
        getchar();
        
        printf("Selectionnez votre status civile:");
       c = getchar();
       
    
        switch (c)
        {
                        case 'c':
                             printf("celibataire.");
                             break;
                        case 'C': 
                             printf("celibataire.");
                             break;  
                        case 'a':
                             printf("un autre cas.");
                             break;
                        case 'A':
                             printf("un autre cas.");
                             break;
                        case 'm':
                             printf("marie.");
                             break;
                        case 'M':
                             printf("marie.");
                             break;
                        case 'd':
                             printf("divorce.");
                             break;
                        case 'D':   
                             printf("divorce."); 
                             break;
      
      printf("\n");
     
        return 0;   
    }
    }

    when i get 2
    Code:
        printf("Selectionnez votre status civile:");
    in dos mode i put in the letter "M" (for marie which is married) and Dos just quits

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 09:19 PM
  2. [Request] Need Help Plz
    By TylerD in forum Tech Board
    Replies: 4
    Last Post: 01-03-2009, 08:54 AM
  3. plz help me with simple string comparison.
    By MegaManZZ in forum C++ Programming
    Replies: 11
    Last Post: 02-18-2008, 12:11 PM
  4. Anyone plz help me
    By Rose_Flowers in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-17-2003, 12:01 PM
  5. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 08:44 AM

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