# C++ switch, no idea.



## dm01 (Oct 10, 2006)

This is a school project.


```
//File Name: numeral_conversion.cpp
//Purpose: To convert roman numerals into arabic digits.
//Notes: Possible re-tooling for other numbering systems.
//completely impossible!!!

#include <iostream>
#include <conio.h>
void main()
{
	//allocation of storage for variables
	int arabic_base;

	cin >> code(numeral)
	{
		case 'I' : arabic_base = 1;
			break;
		case 'V' : arabic_base = 5;
			break;
		case 'X' : arabic_base = 10;
			break;
		case 'L' : arabic_base = 50;
			break;
		case 'C' : arabic_base = 100;
			break;
		case 'D' : arabic_base = 500;
			break;
		case 'M' : arabic_base = 1000;
			break;
	}

// I have no idea how this is supposed to work. Someone help me.
```
The idea of the program is to write out numbers written in Arabic numerals into Roman numerals. I think I need C++ to recognize place value (that part was not explained in class very well) and I think a switch can be configured to do so. The problem is I don't know how these switch things work. The example above was pretty much copied out of the textbook. I thought I'd ask here before going for extra help with the lady with the weird accent no one can understand and has not been definitively placed as to origin.

Someone please help before I completely lose my mind and throw my manriki at the monitor (again)! I already crashed my machine over a stupid infinite loop error, so I am being careful this time.


----------



## cunaguaro (Oct 7, 2008)

hello dm01, 

I don't really know or understand "arabic digits" but here is how you declare a switch statement:


```
switch(this){
case 1 : doThis();
             break;

case 2 : doThis2();
             break;

default : doThat();
}
```
is common to use switch statements to replace if-else statements, and what is meant by the code above is similar to this:


```
if(this == 1)
 { 
   doThis();
 }
  esle if(this == 2)
  {
    doThis2();
}
 else {
       doThat();
}
```

So what im guessing (and i don't mean to do your homework for you) what you need is something like this:


```
#include <iostream>
using namespace std; 

int main(){

int arabic;
char* roman;


cin >> arabic;

switch(arabic){
case 1 : roman = "I"; 
             break;
case 2 : roman = "II";
             break;
case 3 : roman = "III";
             break;
case 4 : roman = "IV";
            break;
// and so on...
}

cout << "roman: " << roman;

return 0;
}
```


----------



## dm01 (Oct 10, 2006)

That's almost exactly what I need, I think. There are a couple of stupid loops I need to figure out (extra credit) but I can handle that (I hope).

I'll try what you suggested and see how it goes.


----------

