# Help my program is giving a problem

Show 80 post(s) from this thread on one page
Page 1 of 5 12345 Last
• 01-29-2011
zangetsu
Help my program is giving a problem
My program is giving me a problem when i error check it an run it after i input wrong data it skips the thing an moves on an also i need guidance or a hint as to how the time minus thing and what exactly is rounded time as i was instructed to put it in but im not exactly sure as to what it is

Code:

```#include <stdio.h> #include <stdlib.h> #include <math.h> int main() { char vehicle[15]; int car; int truck; int hrsn, minn; int hrso, mino; int time; int rt; hrsn=0; hrso=0; minn=0; mino=0; printf("Where you driving a car or truck?\n"); scanf("%s", &vehicle ); printf("What Hour did the %s enter the lot? (0-23)\n", vehicle); scanf("%d",&hrsn); if((hrsn<0 || hrsn>23)) {     printf("\a\a\a Please Input Value from 0-23!\n"); } else {     printf("What Minute did the %s enter the lot? (0-59)\n", vehicle);     scanf("%d",& minn); } if((minn<0 || minn>59)) {     printf("\a\a\a Please Enter Correct Minute Between 0-59!\n"); } else {     printf("What Hour did the %s leave the lot? (0-23)\n", vehicle);     scanf("%d",& hrso); } if((hrso<0 || hrso>23)) {     printf("\a\a\a Please Enter the Correct Time Between 0-23!\n"); } else {     printf("What Minute did the %s leave the lot? (0-59)\n", vehicle);     scanf("%d",& mino); } if(mino<0 || mino>59) {     printf("\a\a\a PLease Enter the Correct time between 0-59!\n"); } else { rt = hrso - hrsn && mino - minn; printf("Time in %d:%d\n", hrsn, minn); printf("Time out %d:%d\n", hrso, mino); printf("Parking Time %d\n", time); printf("Rounded time %d\n", rt); } return 0; }```
• 01-29-2011
C_ntua
Yes, what you want is to ask the user to input a correct amount and until he does keep asking. Think that you are a salesman. What you do is
Code:

```printf("Would you by this fine product?"); scanf("%c", c); if (c != 'y') {   printf("Oh, well, have a nice day sir");   fireEmployee(); } else {   printf("Nice! We aslo have this coupon..."); }```
what you want is:
Code:

```printf("Would you by this fine product?"); scanf("%c", c); while (c != 'y') {     printf("Please reconsider");     scanf("%c", c); } printf("Nice! We aslo have this coupon...");```
Try replacing the if-else with while.

As for the rounded time is not clear like that. Maybe the total time in minutes? Maybe rounding up the time to hours? Your line of code for rt = ... is definitely not doing what you want (&& is the logical AND).
• 01-29-2011
claudiu
The key concept to remember here is the word "aslo". Lol, j/k ;)
• 01-29-2011
zangetsu
Thx C_ntua i'll try it an get back to u and for the example u have given me can that work for words like with what i have i would definately need error checking in words for example for the user to input the words car or truck only, can your example be used like right here:
"(c != 'y')"
be used like (c != 'car') then blah blah blah
• 01-29-2011
Quote:

My program is giving me a problem when i error check it an run it after i input wrong data it skips the thing an moves on an also i need guidance or a hint as to how the time minus thing and what exactly is rounded time as i was instructed to put it in but im not exactly sure as to what it is
=== Whew! What a read, Zangetsu! === :p :p :D :D

You may thank God almighty that you're not an English major!
• 01-30-2011
xniinja
Code:

```printf("Would you by this fine product?"); scanf("%c", c); while (c != 'y') {     printf("Please reconsider");     scanf("%c", c); } printf("Nice! We also have this coupon...");```
Is the point to ........ the costumer off? I would go with this

Code:

```int loop = 0; ... printf("Would you by this fine product?"); scanf("%c", c); while (c != 'y' || loop >= 50) {     loop++;     printf("Please reconsider");     scanf("%c", c);     } if (loop > 2) {     printf("well, have a nice day then..."); } else {     printf("Nice! We also have this coupon..."); }```

• 01-30-2011
Quote:

I don't "by" that! :p :p :p
• 01-30-2011
xniinja
lol... I recognized that after I posted it, I fixed aslo though. :D
• 01-30-2011
zangetsu
k i input the while statements and they worked so thanx very much C_ntua and everyone else who gave valid input and not jokes.lol Is there a way to do error checking for words because i would need for the user to input the words car or truck only is this possible i thought of maybe doing something to count the words car or truck so if the input is greater than 3 characters then its not the word car so is this line of thinking even possible?
• 01-30-2011
zangetsu
I worked on the time section pls run it and tell me if im doing the right thing cause now i think i might have confused myself a bit

Code:

```#include <stdio.h> #include <stdlib.h> #include <math.h> int main() { char vehicle[15]; int car; int truck; int hrsn, minn; int hrso, mino; int hr; //final hour int min; //final minute hrsn=0; hrso=0; minn=0; mino=0; hr=0; min=0; printf("Where you driving a car or truck?\n"); scanf("%s", &vehicle ); printf("What Hour did the %s enter the lot? (0-23)\n", vehicle); scanf("%d",&hrsn); while((hrsn<0 || hrsn>23)) {     printf("\a\a\a Please Input Value from 0-23!\n");     scanf("%d",& hrsn); } {     printf("What Minute did the %s enter the lot? (0-59)\n", vehicle);     scanf("%d",& minn); } while((minn<0 || minn>59)) {     printf("\a\a\a Please Enter Correct Minute Between 0-59!\n");     scanf("%d",& minn); } {     printf("What Hour did the %s leave the lot? (0-23)\n", vehicle);     scanf("%d",& hrso); } while((hrso<0 || hrso>23)) {     printf("\a\a\a Please Enter the Correct Time Between 0-23!\n");     scanf("%d",& hrso); } {     printf("What Minute did the %s leave the lot? (0-59)\n", vehicle);     scanf("%d",& mino); } while(mino<0 || mino>59) {     printf("\a\a\a PLease Enter the Correct time between 0-59!\n");     scanf("%d",& mino); } { if (hrsn < (hrso - 1) && minn > mino) { hrso = hrso - 1; mino = mino + 60; } if (mino - minn > 1 && mino - minn < 30) { mino = minn+30; } else if (mino - minn > 30 && mino - minn < 60) { mino = minn + 60; } else { mino = minn + 00; } hr = (hrso-hrsn); min = (mino - minn); printf("Time in %d:%d\n", hrsn, minn); printf("Time out %d:%d\n", hrso, mino); printf("Parking Time %d:%d\n", hr, min); } return 0; }```
• 01-30-2011
"Doctor, I may have a pain."

Please be specific with what the problem is!
• 01-31-2011
zangetsu
The time aspect of the program in subtracting the time i would like your advice on it to c if what i did was right or if u have any advice or anything like that basically your critique on it
• 01-31-2011
If it's accurate - it's OK. Run-time and clarity are not an issue for the code. It's short and simple.

IMO, you don't need to include either math.h or stdlib.h, and your code should be indented so the subordinate lines of code are indented 2 to 4 spaces.

Code:

```do {   print something   ask for input with scanf }while(input value was etc.) //looks a lot easier to understand and debug, than do { print something ask for input with scanf } while(input value is etc.)```
After you've been programming for awhile, your eye will become trained, if you use standard indentation, to readily pick up on syntax bugs in your code. Properly indented code allows us to also use our trained eyes, to quickly spot some kinds of common errors.

If you want people to study your code for free, why not help them to do so?
• 01-31-2011
zangetsu
I'm trying to have my program do word error checking but for some reason its not working i want the user to input either the words car or truck this is what i have done so far!

Code:

```#include <stdio.h> #include <stdlib.h> #include <ctype.h> int main() { char *vehicle; int car; int truck; int hrsn, minn; int hrso, mino; int hr; //final hour int min; //final minute hrsn=0; hrso=0; minn=0; mino=0; hr=0; min=0; printf("Where you driving a car or truck?\n"); scanf("%s", &vehicle ); while(vehicle != "car" && vehicle != "truck") {     printf("Please input the words Car or Truck: ");     scanf("%s",&vehicle); } printf("What Hour did the %s enter the lot? (0-23)\n", vehicle); scanf("%d",&hrsn); while((hrsn<0 || hrsn>23)) {     printf("\a\a\a Please Input Value from 0-23!\n");     scanf("%d",& hrsn); } {     printf("What Minute did the %s enter the lot? (0-59)\n", vehicle);     scanf("%d",& minn); } while((minn<0 || minn>59)) {     printf("\a\a\a Please Enter Correct Minute Between 0-59!\n");     scanf("%d",& minn); } {     printf("What Hour did the %s leave the lot? (0-23)\n", vehicle);     scanf("%d",& hrso); } while((hrso<0 || hrso>23)) {     printf("\a\a\a Please Enter the Correct Time Between 0-23!\n");     scanf("%d",& hrso); } {     printf("What Minute did the %s leave the lot? (0-59)\n", vehicle);     scanf("%d",& mino); } while(mino<0 || mino>59) {     printf("\a\a\a PLease Enter the Correct time between 0-59!\n");     scanf("%d",& mino); } { if (hrsn < (hrso - 1) && minn > mino) { hrso = hrso - 1; mino = mino + 60; } if (mino - minn > 1 && mino - minn < 30) { mino = minn+30; } else if (mino - minn > 30 && mino - minn < 60) { mino = minn + 60; } else { mino = minn + 00; } hr = (hrso-hrsn); min = (mino - minn); printf("Time in %d:%d\n", hrsn, minn); printf("Time out %d:%d\n", hrso, mino); printf("Parking Time %d:%d\n", hr, min); } return 0; }```
• 01-31-2011
tabstop
You should use strcmp to compare strings.
Show 80 post(s) from this thread on one page
Page 1 of 5 12345 Last