ok know it will exacut till pay input

This is a discussion on ok know it will exacut till pay input within the C Programming forums, part of the General Programming Boards category; OK. The info up to here has been grate I am learning a lot more from talking to people than ...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    18

    ok know it will exacut till pay input

    OK. The info up to here has been grate I am learning a lot more from talking to people than this trial and error that I had been using, So here is the problem untill the salection of the pay rate it is runing fine. (it did Compile) but I get nothing after the reqest of the pay rate.

    Code:
    #include <stdio.h> 
    int main (void)
    /*Using comp. Dev C/C++ information searched on the net on case structure and printf usage along with sugestions
    from programing sites like program basics and cprograming, I have put togeather this file.*/ 
    { 
        char name [30];
        int pay = 0;       /*selected from case group by alph corispondant # */ 
        int hours = 0;      /*user input with if elas statments */ 
        int hlhrs = 0;      /*user input in conjunction with the if eals statments */ 
        int ot = 0;         /*mathmatical calculation with in the if eals than statments*/ 
        int othol = 0; 		 
        int check = 0;      /*total amount of pay for the week*/       
            printf ("What is your Name?"); 
            scanf ("%s", name); 
            printf ("Good Day to you %s."); 
            printf("Please chose one of the following choses so we know the amount of your hourly pay.\n");
            printf ("1 : $10.00 an hour.");
            printf ("2 : $20.00 an hour.");
            printf ("3 : $30.00 an hour.");
            printf ("4 : $50.00 an hour."); 
              scanf ("%d", pay);      
     switch (pay) {
            case 1:
                    pay = 10;
                    break;
            case 2:
                    pay = 20;
                    break;
            case 3:
                    pay = 30;
                    break;
            case 4:
                    pay = 50;
                    break;
    		 default:
    		   pay = 10;
    		   break;
    
    this is were I get no propt.. any sugestions :o :mad:
    printf ("So How many Hours did you work?"); scanf ("%d", hours); if (hours <= 40); { check = pay * hours; printf ("Your pay this week will be $",check); } if (hours > 40); { printf ("How many Holiday and Sunday Hours did you have? IF any!"); scanf ("%d", hlhrs); printf ("How many Overtime hours did you work? If any!"); scanf ("%d", ot); }// end if eals check = ((hlhrs * 2) + (ot * 1.5)+ (hours - (hlhrs + ot))); printf("Your pay this week will be $",check); }

  2. #2
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    firstly to say that your programe is not correctly aligned. thats where u have gone wrong in few places. with qucik glance on your code i found few bug which eventually end up with an error.
    1.
    Code:
    printf ("Good Day to you %s.",name);
    should specilfy the variable name in order to print

    2. you switch had a opened preces but no closing braces
    3.
    Code:
    scanf ("%d", &pay);   
    scanf ("%d", &hours); 
    scanf ("%d", &hlhrs); 
    scanf ("%d",& ot);
    these scanf statments need & as they are not string they need the address of operation in order to read the data from the user.

    4.
    Code:
    printf ("Your pay this week will be $%d",check);
     printf("Your pay this week will be $%d",check);
    u are trying to print the result which actually dont print as there is format specifier mention in the printf fucntion which actually end up with an error

    ssharish2005

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,337
    1. If you're going to be using a gcc based compiler, then figure out how to enable as many warnings as possible. This compiler in particular is capable of telling you when you've messed up with printf() and scanf()

    2. Learn to format code. I don't care what you do so long as you're consistent. Any consistent approach will easily tell you that you missed a brace (see comments below)

    My suggestion would be fix the missing brace, then set up the compiler so it produces the list of warnings shown below. You should be able to add the extra command line options "-W -Wall -ansi -pedantic -O2" to the compiler settings for your project.

    Here's your code, reformatted
    Code:
    #include <stdio.h>
    int main(void)
    {
        char name[30];
        int pay = 0;                /*selected from case group by alph corispondant # */
        int hours = 0;              /*user input with if elas statments */
        int hlhrs = 0;              /*user input in conjunction with the if eals statments */
        int ot = 0;                 /*mathmatical calculation with in the if eals than statments */
        int othol = 0;
        int check = 0;              /*total amount of pay for the week */
    
        printf("What is your Name?");
        scanf("%s", name);
        printf("Good Day to you %s.");
        printf("Please chose one of the following choses so we know the amount of your hourly pay.\n");
        printf("1 : $10.00 an hour.");
        printf("2 : $20.00 an hour.");
        printf("3 : $30.00 an hour.");
        printf("4 : $50.00 an hour.");
        scanf("%d", pay);
        switch (pay) {
        case 1:
            pay = 10;
            break;
        case 2:
            pay = 20;
            break;
        case 3:
            pay = 30;
            break;
        case 4:
            pay = 50;
            break;
        default:
            pay = 10;
            break;
        }                           /*!! Missing */
        printf("So How many Hours did you work?");
        scanf("%d", hours);
    
        if (hours <= 40);           /*!! what's this ; doing here? */
        {
            check = pay * hours;
            printf("Your pay this week will be $", check);
        }
        if (hours > 40);           /*!! what's this ; doing here? */
        {
            printf("How many Holiday and Sunday Hours did you have? IF any!");
            scanf("%d", hlhrs);
    
            printf("How many Overtime hours did you work? If any!");
            scanf("%d", ot);
    
        }                           /* end if eals */  /*!! what 'else' are you on about? */
        check = ((hlhrs * 2) + (ot * 1.5) + (hours - (hlhrs + ot)));
        printf("Your pay this week will be $", check);
    }
    And here are the error messages you should be seeing. Pay close attention to every single one of them.
    Code:
    $ gcc -W -Wall -ansi -pedantic -O2 foo.c
    foo.c: In function ‘main’:
    foo.c:14: warning: too few arguments for format
    foo.c:20: warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘int’
    foo.c:39: warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘int’
    foo.c:41: warning: empty body in an if-statement
    foo.c:44: warning: too many arguments for format
    foo.c:46: warning: empty body in an if-statement
    foo.c:49: warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘int’
    foo.c:52: warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘int’
    foo.c:56: warning: too many arguments for format
    foo.c:9: warning: unused variable ‘othol’
    foo.c:57: warning: control reaches end of non-void function

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. input redirection
    By sashaKap in forum C Programming
    Replies: 6
    Last Post: 06-25-2009, 01:59 AM
  2. I would love some input on my BST tree.
    By StevenGarcia in forum C++ Programming
    Replies: 4
    Last Post: 01-15-2007, 12:22 AM
  3. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  4. Structure and Linked List User Input Question
    By kevndale79 in forum C Programming
    Replies: 16
    Last Post: 10-05-2006, 11:09 AM
  5. Getting standard input
    By winsonlee in forum C Programming
    Replies: 1
    Last Post: 04-04-2004, 08:51 PM

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