Thread: using files

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

    using files

    I am in need of more advice, my program is working but I am not geting the answer that I got by calculation that I should have gotten in the program. would someone tell me what I am doing wrong with the coding on my math function. Second to last line of code.

    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;	/*mathmatical calculation with in the if eals than statments */
        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;
    }                           
    		// Section 2.0 = input of hours worked
        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);
    }
        eals 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);
    }// end of program

  2. #2
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    It's else if not eals if also put a & before passing integers in scanf statements to pass a reference rather than the number itself,
    Code:
    scanf("%d", &myint);
    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;	/* mathmatical calculation with in the if eals than statments */
        int check = 0;      /* total amount of pay for the week */
    
        printf("What is your Name?\n> ");
        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.\n");
        printf("2 : $20.00 an hour.\n");
        printf("3 : $30.00 an hour.\n");
        printf("4 : $50.00 an hour.\n> ");
        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;
        }                           
    		/* Section 2.0 = input of hours worked */
        printf("So How many Hours did you work?\n> ");
        scanf("%d", &hours);
    
        if (hours <= 40) {
            check = pay * hours;
            printf("Your pay this week will be $", check);
        }
        else if (hours > 40) {
            printf("How many Holiday and Sunday Hours did you have? IF any!\n> ");
            scanf("%d", &hlhrs);
    
            printf("How many Overtime hours did you work? If any!\n> ");
            scanf("%d", &ot);
        }
          
        check = ((hlhrs * 2) + (ot * 1.5) + (hours - (hlhrs + ot)));
        printf("Your pay this week will be $", check);
        
        return 0;
    }

  3. #3
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    Well in the second to last line of actual code I see a problem.

    Code:
     printf("Your pay this week will be $", check);
    Do you see it yet?

    It kind of looks like you are wanting everybody else to debug your program for you. I remember doing an awful pile of editing on your program to demonstrate to you how things were done. When I was done, I had (on my machine anyway) a program which compiled with no warnings. I did not give that program to you, as I figured it would help you to be lazy. Now you come back with the same thing, and Salem gets a number of warnings. You should have been able to produce code that had no warnings. Be that as it may, even if you are really working hard on this, it has the appearance that you are not. There are plenty of slackers who show up here wanting their homework done, and so if you don't want to be lumped in with those sorts of people, then you might want to consider demonstrating some gumption, and stop reposting problems that ought to have been fixed with the help you had already.

    ~/

  4. #4
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    Oh yeah, missed that one.

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

    wait a sec ??!!

    I asked about the math formula not if I had made any other mistake I made the minor changes at work on txt pad. I just lodded it up and found the iteams you were talking about ... Im not being lazy I am trying to find an editor that works in better form than miracle C and I think that DEV C++ is doing a grate job. as for the info you gave me I would have eventualy found it Im sure but I am trying to do this. I dont ask unless I cant find it. So if you are not wanting to help than fine. I am learning more from you all than I did on the class night that covered the case and if else statments... I was told were to find the best help so that is why I am here.

  6. #6
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    Well, I think you should first follow Salem's advice and crank up the warnings on your compiler. If you don't know how to do that, read the documentation. Then, when you get the compiler to generate some warnings, go to the lines which it indicates, and fix the code.

    As far as your formula, anything under 40 hours seems to work fine, but your method of calculating overtime needs work. As well, your program logic is not quite what you want. The way it is now, even if you only input 40 hours or less, you still get two different outputs for the amount of money. I am thinking that you will want to move this:

    Code:
     check =
                        ((hlhrs * 2) + (ot * 1.5) + (hours - (hlhrs + ot)));
                    printf("Your pay this week will be $%d", check);
    into the else if statement.

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

    kermit

    thanks I will look at that right away .... but as for the warnings since I have moved over to Dev C++ I am asuming the docs your refering to is the doc file from install? I have tryd that and am not finding the warnings info.

    I want to learn this that is why I am here. the more helpfull my software is the more I can understand and learn. thks

    Edit:
    I had to reinstall Dev C++ The help file was bad and know i see the instructions for the warnings thanks a lot people, I am getting there.
    Last edited by fmchrist; 01-02-2006 at 03:56 PM.

  8. #8
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by fmchrist
    thanks I will look at that right away .... but as for the warnings since I have moved over to Dev C++ I am asuming the docs your refering to is the doc file from install? I have tryd that and am not finding the warnings info.
    Dev-Cpp Project Options (Adding Additional Compiler Switches)

    A build using the code from your original post with these added parameters.
    Code:
    C:/Dev-Cpp/bin/gcc.exe -c  -ansi -g -Wall -pedantic -o "Gnu/main.o"  "main.c"
    main.c: In function `main':
    main.c:14: warning: too few arguments for format
    main.c:20: warning: format argument is not a pointer (arg 2)
    main.c:38: error: syntax error before '/' token
    main.c:40: warning: format argument is not a pointer (arg 2)
    main.c:45: warning: too many arguments for format
    main.c:47: error: `eals' undeclared (first use in this function)
    main.c:47: error: (Each undeclared identifier is reported only once
    main.c:47: error: for each function it appears in.)
    main.c:47: error: syntax error before "if"
    main.c:57: warning: too many arguments for format
    main.c:9: warning: unused variable `othol'
    main.c: At top level:
    main.c:58: error: syntax error before '/' token
    c:\Dev-Cpp\bin\make.EXE: *** [Gnu/main.o] Error 1
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ressources files
    By mikahell in forum Windows Programming
    Replies: 4
    Last Post: 06-19-2006, 06:50 AM
  2. add source files to embedded VC 4.0
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2006, 03:28 AM
  3. *.cpp and *.h files understanding
    By ElastoManiac in forum C++ Programming
    Replies: 4
    Last Post: 06-11-2006, 04:45 AM
  4. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 11:46 AM
  5. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 02:41 PM