![]() |
| | #1 | |
| Registered User Join Date: Dec 2005
Posts: 18
| ok know it will exacut till pay input 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;
| |
| fmchrist is offline | |
| | #2 |
| Protocol Test Engineer 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);
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);
4. Code: printf ("Your pay this week will be $%d",check);
printf("Your pay this week will be $%d",check);
ssharish2005 |
| ssharish2005 is offline | |
| | #3 |
| and the hat of Jobseeking 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);
}
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 | |
![]() |
| Thread Tools | |
| Display Modes | |
|
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 |