473,834 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C++ Roman to Arabic

2 New Member
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_n umber=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(cha r roman[]);
roman;//


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






void returnRoman(cha r 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_numbe r<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 6558
mookbooker
2 New Member
I had to build then compile then I forgot about the "green arrow" start debugging
Aug 30 '07 #2
rhitam30111985
112 New Member
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 Recognized Expert Top Contributor
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
4616
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 treated as their numerical values? I don't think this is a especially problematic thing to do, but I don't want to re-invent the wheel. Thanks Ivo
2
7467
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 make a show.asp in which user can see that arabic data in table from database on internet. FOR english version i have make that project completely.
1
4013
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 from database after i uploaded site to the hosing server .... All the arabic data retreived from database using Asp appears as question marks ??????? and only staic arabic written in asp pages appears well but which retreived from database...
17
8359
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 role is mainly advisory and server management. I have very little to do with content or page generation, so it's not something I can do myself -- I have to persuade other people to do it.
6
3115
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 displayed in Arabic but the numbers were Latin. In other parts of my app ,Arabic numerals would appear as expected. I found an MSDN link to the following web page that mentioned there was an issue with the current DropDownList and ListBox ASP.NET...
13
4395
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
453
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 forms, message boxes in Arabic also. Does it mean that my application will have duplicate forms. One for Arabic and One for Non-Arabic. I am planning to use Access 2000. How will the arabic tests be written in the database? Can i be able to...
6
3123
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 keyboard language by pressing ALT+SHIFT (or by changing the language manually elsewhere) each time he wants to shift from one language to another.
2
1966
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 help making the program short and use functions too. I'm posting my code here but i'm not posting the cin statements and the validating user entry loops. i'm just posting the if statements that i used. so here is my code: thousands =...
0
9797
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10793
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10547
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9331
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6954
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5626
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5793
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3977
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.