Hello,
I don't know bandit_77, but I am also trying to write the exact program that he requested help on. I doubt I know as much as the original poster because I am very new to programming. So the answer to the "goldilocks" problem is, ""Woah, back up Einstein, I'm new at this" Although, unlike bandit, I am willing to give it a try.

I am having trouble coming up with a way to "test if it's above '9', and if it is reset it to '0' and add 1 to the next column. If a letter, test for 'Z'" as WaltP suggested.

Here is my first attempt. Be warned it's pretty ugly and my compiler just about had a heart attack after trying to compile it :$

#include <stdio.h>

main()

{
	char license_plate[6]; = "0123456789abcdef"
	int i;

	for ( i = 0 ; i < 10 ; i++ ) {
  printf( "The next license Plate is=%06d\n", i );
}

	while (?)

	{
		printf("Please enter the license plate >");
	        scanf("%s", license_plate);
		

	
	}
}

I know it is a mess. I'm pretty sure some things are out of place in there. I'm going to pick up a "C for dummies book" tomorrow. Thanks.

Recommended Answers

All 6 Replies

Hello,
I don't know bandit_77, but I am also trying to write the exact program that he requested help on. I doubt I know as much as the original poster because I am very new to programming. So the answer to the "goldilocks" problem is, ""Woah, back up Einstein, I'm new at this" Although, unlike bandit, I am willing to give it a try.

I am having trouble coming up with a way to "test if it's above '9', and if it is reset it to '0' and add 1 to the next column. If a letter, test for 'Z'" as WaltP suggested.

Here is my first attempt. Be warned it's pretty ugly and my compiler just about had a heart attack after trying to compile it :$

#include <stdio.h>

main()

{
	char license_plate[6]; = "0123456789abcdef"
	int i;

	for ( i = 0 ; i < 10 ; i++ ) {
  printf( "The next license Plate is=%06d\n", i );
}

	while (?)

	{
		printf("Please enter the license plate >");
	        scanf("%s", license_plate);
		

	
	}
}

I know it is a mess. I'm pretty sure some things are out of place in there. I'm going to pick up a "C for dummies book" tomorrow. Thanks.

Hey!! At least you used CODE tags!!! Bravo!!!

Since you're new to programming, learn to format your code NOW! Don't wait.... It'll come in handy later.

First thing to understand is the relationship of ASCII digits and letters to their value. Every character has a value:
'0' - '9' = 48 - 57
'A' - 'Z' = 65 - 90
'a' - 'z' = 97 - 122

So you can use the characters as if they were numbers. For example, if chr is '2', you can convert it to the value 2 with either: chr = chr - 48; chr = chr - '0'; Also notice the groups of characters are not together. You have to take that into account.

Now let's look at your code: main() main() is ALWAYS an int: int main() char license_plate[6]; = "0123456789abcdef" You defined the array as holding 6 character and are trying to cram 16 characters into it.

for ( i = 0 ; i < 10 ; i++ ) 
{
    printf( "The next license Plate is=%06d\n", i );
}

This prints the value of i 10 times:
000000
000001
000002
... while (?) Probably won't compile :icon_wink:
Also, with no idea what you think you need, we can't very well give you hints...

printf("Please enter the license plate >");
scanf("%s", license_plate);

1) why ask for the plate this late
2) See this
3) the variable has been defined holding a constant string. Can't do that because the string cannot be overwritten.

Start again and write one step of the program at a time:
1) Accept plate input, compile, test
2) Output the plate, compile, test
etc...

And last, this post is considered hijacking. The OP, even though he has the same program, you are asking for help on his thread. It's difficult to help two people in the same thread. So I moved it.

Thank you for your help and advice. I have expanded on my program and I have come up with the following code. It is still not done and I would appreciate any more helpful hints or suggestions.

#include <stdio.h>
#include <string.h>

main()
{
       char license_plate[6];
       char answer;
       int counter=0;
       int number,letter1,letter2,letter3,check1,check2;


       while (answer = 'Y')
       {
               printf("Please enter the license plate >");
               scanf("%s", &license_plate);

       if (license_plate[5])='9';
       else
          { license_plate[4]++;
            license_plate[5] = 0;
            }

       for (counter = 0; counter < 6; counter++)
             {
               printf("%c",license_plate[counter]);
             };
       printf("\n\n\nWould you like to continue running the program? (Y)es or (N)o >");

               scanf("%s",&answer);



       }
return(0);}

I am receiving a "expected primary-expression before '=' token" error on the following line:

if (license_plate[5])='9';

Any ideas on how to fix this? I want to say thanks again for your help!

If you look up the format of the if statement, you will find the statement should be

if (license_plate[5] == '9')
{
}

If you look up the format of the if statement, you will find the statement should be

if (license_plate[5] == '9')
{
}

And you have the same problem as WaltP said with your while() statement: while (answer = 'Y') should be: while (answer == 'Y') The difference between the two is that the first one says: assign 'Y' to 'answer' and check if this action was a succes.
The second statement says: Check if the value stored in answer is the same as ' Y'.
This is a typical 'newbie' (with all respect) error, so don't worry about it.

And this statement won't work because 'answer' is not assigned a value before entering this loop. So define answer as char answer = 'Y'; And change main() to : int main() as was mentioned earlier bij WaltP

regards Niek

Hey Neik, you should quote the post you're commenting on, not the last one you see. From your comment I thought I screwed up the while statement at first... :icon_lol:

Hey pWalt:

It's Niek
The reason I quoted your post was because the error you saw was very much related to the error I saw, in this way I wasn't trying to take all the credits, but show the OP that it was in fact YOUR observation :)

And I guess most people here know your not a complete plonker ;)

nIEk

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.