I am currently trying to write a program to simply output roman numerals (not convert-as on many previous threads) from 1-99..
This is the logic/code I have tried so far, but I am certain that it isn't correct apart from the fact that it isnt compiling.

#include<stdio.h>
int main(void)
{
	int x[3],xfront,xback,i;
	xfront=x/10;
	xback=x%10;

	switch (xback=x[2])  {
		case '1' : printf("I");
		break;
		case '2' : printf("II");
		break;
		case '3' : printf("III");
		break;
		case '4' : printf("IV");
		break;
		case '5' : printf("V");
		break;
		case '6' : printf("VI");
		break;
		case '7' : printf("VII");
		break;
		case '8' : printf("VIII");
		break;
		case '9' : printf("IX");
		break;
		default : printf(" ");
		}

	switch (xfront=x[1]) {
		case '1' : printf("X");
		break;
		case '2' : printf("XX");
		break;
		case '3' : printf("XXX");
		break;
		case '4' : printf("XL");
		break;
		case '5' : printf("L");
		break;
		case '6' : printf("LX");
		break;
		case '7' : printf("LXX");
		break;
		case '8' : printf("LXXX");
		break;
		case '9' : printf("XC");
		break;
		default : printf(" ");
 		}
		
		for (x=1;x<=99;x++) 
		{
		printf("%d%d",xfront,xback);
		}
		
	getchar ();
	getchar ();
	return 0;
}

For example when i declared variable x[3] i was referring to 3 spaces to store memory in _ _ \0, so that the first space will be the xfront and the second xback.

But when i wrote the loop i had to do the counter i.e. x from 1-99 and the compiler gave an error.

i tried to remediate to this by :

y=*x;
		for (y=1;y<=99;y++) 
		{
		printf("%d%d",xfront,xback);

[boilerplate_help_info]

Posing requests for help must be well thought out if you want help quickly and correctly.  Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful?  Check your post with these checkpoints - what is it [i]you[/i] missed:
[list=1]
[*]Ask a question that can be answered. Do not ask
- What's wrong with my code?
- Why doesn't this work?
- Anything else that does not give us useful information
[*]Post your code.  If we don't know what you did, how can we possibly help?
- Use [b]PROPER FORMATTING[/b] -- see this
- Use CODE Tags so your formatting is preserved.
If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable
[*]Explain what the code is supposed to do.  If we don't know where the target is, how can we help you hit it?
[*]Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
[*]If you have errors, post them! We can't see your screen.  We can't read your mind. You need to tell us what happened.
[*]Do [b]not[/b] ask for code. We are not a coding service. We will help you fix your code. 
    If anyone posts working code for you, they are a cheater. 
    If you use that code [i]you[/i] are a cheater.
[*]Do [b]not[/b] bore us with how new you are. We can tell by your code.
- Do not apologize. We were all new, and unless you are completely 
  brain dead you will get better.
- Do not ask us to "take it easy on you."
- Do not say "I don't know what's going on." That's obvious since
  you posted for help. Use that time wisely by [b]explaining[/b] as best 
  you can so we can help.
[*][b]Do not post your requirements and nothing else. [/b]We view that as a lazy do-nothing student that wants us to do their work for them. That's cheating and we [i]will[/i] be hard on you.
[*]Do not attach files except when absolutely necessary. Most of us are not going to download file.  Add the information to your post.
[*][b]Do not tell us how urgent it is.[/b] Seriously, for us there is no urgency at all. Many that can help will ignore any URGENT or ASAP requests.
[/list]
Think more about your next post so we don't have to play 20 questions to get the info we need to help you.

[/boilerplate_help_info]

well let me adapt the question in a manner that perhaps makes more sense then.

The purpose of the program is to output the roman numerals from 1-99 (and use the switch statement)

From the code above how can is there a simple way where I can initialize the variables xback and xfront please such that they refer to the second and first value of x respectively?

Maybe you should put something more in this loop:

for (x=1;x<=99;x++) 
		{
		printf("%d%d",xfront,xback);
		}

Nothing gives roman numbers here, xfront and xback do not change, only counter changes and it is not used for anything.

I would make one function called roman_number taking int argument. I would then print roman_number(x).

Edited 5 Years Ago by pyTony: n/a

I changed the first part to the following

{
int i, front, back;
for(i=1; i<=100; i++)
{
front = i/10;
back = i%10;

and included the two switch statements in this for loop .. where x[1] and x[2] where replaced by front and back and the program worked fine then.

This question has already been answered. Start a new discussion instead.