C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 01-02-2006, 06:34 AM   #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;
Quote:
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); }
fmchrist is offline   Reply With Quote
Old 01-02-2006, 07:05 AM   #2
Protocol Test Engineer
 
ssharish2005's Avatar
 
Join Date: Sep 2005
Location: fseek(UK)
Posts: 1,324
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
ssharish2005 is offline   Reply With Quote
Old 01-02-2006, 07:33 AM   #3
and the hat of Jobseeking
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,688
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
Salem is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 07:42 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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