473,405 Members | 2,294 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

C++ Roman to Arabic

I have a code written out with zero errors but i know my main() function is completely wrong and after i build the solution i compile it and nothing happens!! Not even cout statements please help.

// 2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
using namespace std;

class romanNumerals {
// handles arithmetic operations on Roman Numerals
// conditions maintained in class:
// 0 < num < 3999
public:
void const returnRoman (char roman[]); // returns a roman numeral
void setArabic (int number); // accepts an integer
void setRoman (char* roman); // accepts a roman numeral
bool isError (); // returns true if the most recent operation has caused an error.
private:
int num,M,D,C,L,X,V,I;// the internal representation of the roman numeral
char roman; // the actual roman numeral is not maintained
}; // class romanNumerals






int main()
{
char roman;
int menu=0,output_number=0;
int number =0;
cout << " press 1 to enter arabic number \n press 2 to enter roman numeral " << endl;
cin >> menu;

if(menu==1)
{
number;
output_number = number;
}

else if(menu==2)
{
roman;
output_number = roman;//actually converted into arabic number
}
//need to get output_number value into returnRoman(char roman[]);
roman;//


return 0;
// */
}//end of main






void returnRoman(char roman[])
{
int num;
//takes num (10) and converts it to roman (x)
while (num >=1000)
{
cout << "M" << endl;
num-=1000;

}
while (num >=900 && num<1000)
{

cout << "CM" << endl;
num-=900;

}
while (num >=800 && num<900)
{
cout << "DCCC" << endl;
num-=800;

}
while (num >=700 && num<800)
{

cout << "DCC" << endl;
num-=700;

}
while (num >=600 && num<700)
{

cout << "DC" << endl;
num-=600;

}
while (num >=500 && num<600)
{

cout << "D" << endl;
num-=500;

}
while (num >=400 && num<500)
{

cout << "CD" << endl;
num-=400;

}
while (num >=300 && num<400)
{

cout << "CCC" << endl;
num-=300;

}
while (num >=200 && num<300)
{

cout << "CC" << endl;
num-=200;

}
while (num >=100 && num<200)
{

cout << "C" << endl;
num-=100;

}
while (num >=90 && num<100)
{

cout << "XC" << endl;
num-=90;

}
while (num >=80 && num<90)
{

cout << "LXXX" << endl;
num-=80;

}
while (num >=70 && num<80)
{

cout << "LXX" << endl;
num-=70;

}
while (num >=60 && num<70)
{

cout << "LX" << endl;
num-=60;

}
while (num >=50 && num<60)
{

cout << "L" << endl;
num-=50;

}
while (num >=40 && num<50)
{

cout << "XL" << endl;
num-=40;

}
while (num >=30 && num<40)
{

cout << "XXX" << endl;
num-=30;

}
while (num >=20 && num<30)
{

cout << "XX" << endl;
num-=20;

}
while (num >=10 && num<20)
{

cout << "X" << endl;
num-=10;

}
while (num >=9 && num<10)
{

cout << "IX" << endl;
num-=9;

}
while (num >=8 && num<9)
{

cout << "VIII" << endl;
num-=8;

}
while (num >=7 && num<8)
{

cout << "VII" << endl;
num-=7;

}
while (num >=6 && num<7)
{

cout << "VI" << endl;
num-=6;

}
while (num >=5 && num<6)
{

cout << "V" << endl;
num-=5;

}
while (num >=4 && num<5)
{

cout << "IV" << endl;
num-=4;

}
while (num >=3 && num<4)
{

cout << "III" << endl;
num-=3;

}
while (num >=2 && num<3)
{
cout << "II" << endl;
num-=2;

}
while (num >=1 )
{


cout << "I" << endl;
num-=1;
}


}

void setArabic (int number)// takes arabic number
{

int arabic_number;
cout << " Enter an arabic number between 1 and 3999 " << endl;
cin >> arabic_number;

if(arabic_number<1 || arabic_number >3999)
cout << " Error number out of range " << endl;
number = arabic_number;


}

void setRoman (char* roman)// takes in roman numbers
{
int n=0;
int num =0;



cout << " Enter the Roman numeral atleast I and less than MMMM " << endl;
cin >> roman;

if (roman[n] == 'M')
{
n++;
num +=1000;

}

else if (roman[n]== 'C' && roman[n+1]=='M')
num+=900;
else if (roman[n]== 'D' && roman[n+1+1+1]=='C')
num+=800;
else if (roman[n]== 'D' && roman[n+1+1]=='C')
num+=700;
else if (roman[n]== 'D' && roman[n+1]=='C')
num+=600;
else if (roman[n]== 'D')
num+=500;
else if (roman[n]== 'C' && roman[n+1]=='D')
num+=400;
else if (roman[n]== 'C' && roman[n+1+1]=='C')
num+=300;
else if (roman[n]== 'C' && roman[n+1]=='C')
num+=200;
else if (roman[n]== 'C')
num+=100;
else if (roman[n]== 'X' && roman[n+1]=='C')
num+=90;
else if (roman[n]== 'L' && roman[n+1+1+1]=='X')
num+=80;
else if (roman[n]== 'L' && roman[n+1+1]=='X')
num+=70;
else if (roman[n]== 'L' && roman[n+1]=='X')
num+=60;
else if (roman[n]== 'L')
num+=50;
else if (roman[n]== 'X' && roman[n+1]=='L')
num+=40;
else if (roman[n]== 'X' && roman[n+1+1]=='X')
num+=30;
else if (roman[n]== 'X' && roman[n+1]=='X')
num+=20;
else if (roman[n]== 'X')
num+=10;
else if (roman[n]== 'I' && roman[n+1]=='X')
num+=9;
else if (roman[n]== 'V' && roman[n+1+1+1]=='I')
num+=8;
else if (roman[n]== 'V' && roman[n+1+1]=='I')
num+=7;
else if (roman[n]== 'V' && roman[n+1]=='I')
num+=6;
else if (roman[n]== 'V')
num+=5;
else if (roman[n]== 'I' && roman[n+1]=='V')
num+=4;
else if (roman[n]== 'I' && roman[n+1+1]=='I')
num+=3;
else if (roman[n]== 'I' && roman[n+1]=='I')
num+=2;
else if (roman[n]== 'I')
num+=1;

cout << num << endl; //now actually converted to arabic




}
Aug 29 '07 #1
3 6525
I had to build then compile then I forgot about the "green arrow" start debugging
Aug 30 '07 #2
rhitam30111985
112 100+
uh... i dunno where to start.. plz use code tags in the future.... secondly u havent defined an instance of the class romanNumerals anywhere.. the syntax for member function of the class is wrong .. i am surprised u r not getting any compilation error... apart from that in the main function :
Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3. char roman;
  4. int menu=0,output_number=0;
  5. int number =0;
  6. cout << " press 1 to enter arabic number \n press 2 to enter roman numeral " << endl;
  7. cin >> menu;
  8.  
  9. if(menu==1)
  10. {
  11. number;
  12. output_number = number;//garbage value..since number is local to this block
  13. }
  14.  
  15. else if(menu==2)
  16. {
  17. roman;//here.. i guess default data type is int .. which is local to  this block
  18. output_number = roman;//actually converted into arabic number... this gets a garbage value since roman is uninitialized 
  19. }
  20. //need to get output_number value into returnRoman(char roman[]);
  21. roman;//
  22.  
  23.  
  24. return 0;
  25. // */
  26. }//end of main
  27.  
even if above errors r taken care of... there is no cout to output the result :-P

start with this... and if there r more errors then we will see..
Aug 30 '07 #3
gpraghuram
1,275 Expert 1GB
Hi,
R u facing any issues still or else u are debugging?

Raghuram
Aug 30 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Ivo | last post by:
Hi, An array contains elements of the form , for example IVa, XIXb, LIX and LXIVc. Does anyone have a function which can sort this array in a way a human would expect it to, with the roman letters...
2
by: zahid | last post by:
Hello, Dear Friends, I have to make such type of interface,you can say it a html form. in which a admin can write arabic data and can insert that data or recordsin database in ASP. and i have to...
1
by: NohaKhalifa | last post by:
Dear All , I have a very big problem regarding using Arabic Character set . I'm Developing an Arabic Web Site using Asp and connecting to Access Database . but i have a problem retreiving data...
17
by: thinkfirst | last post by:
Hello CIWAH ... I want to propose full internationalization of three related websites: http://africadatabase.org/ http://people.africadatabase.org/ http://institutions.africadatabase.org/ My...
6
by: Mutley | last post by:
I am finding an issue with the current DropDownList and ListBox ASP.NET Web Controls. I had a system set up for Arabic and a string that I put into a drop down had a number. The letters were being...
13
by: Christopher Benson-Manica | last post by:
Inspired by a thread on clc++, I decided to try it out... #include <stdio.h> #include <stdlib.h> int main( int argc, char *argv ) { int i; int result=0; int this;
0
by: bvcbb | last post by:
Dear all I am supposed to develop a world ready application in C# 2003 (which will run in xp) which should aupport Arabic & Hebrew also. My doubts(Fears) are: 1. Do i have to create all the...
6
by: Michelle Stone | last post by:
Hi I am doing a bilingual .NET application for English/Arabic. On a web form, I have some edit boxes for data entry in Arabic and some for entry in English. Right now the user has to change his...
2
by: bluedemon | last post by:
I've written the program and it works fine. but my instructor said that i can make the program short and use functions in it, but i cant really understand functions that good. so i just need a little...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.