C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 26th, 2012, 06:58 PM
bbeth bbeth is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 1 bbeth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m 45 sec
Reputation Power: 0
Memory & arrays - Storing Roman Numerals into Arrays

First off I hope everyone had a great Thanksgiving. I am writing a program that lets the user enter a number and it is converted and displayed in roman. Then the number as well as the longRoman(in caps), the longRoman, The shortRoman(in caps), and the short roman is stored into two parallel arrays of 20 elements. One array must contain whole number and the other must contain strings.The number that the user enters needs to continue to count up to 20 consecutive numbers. I keep getting an error message "piece is being used without being initialized" and I cannot figure that out. Also I am having trouble with the arrays. If someone could please point me in the right direction it would be greatly appreciated. I had it to where it would put out the roman but now it won't even do that. I feel like I am doing more damage as I go along This is what I have now.






#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
char list [100] [20];




int _tmain( )
{
string roman;
int integer;
int piece;
int Decimal;
int LongRoman;
int ShortRoman;




cout << "Enter an integer and get the long and short roman numbers equivalant to that integer." << endl;
cout << " Enter an integer from 1-5000" << endl;
cin >> integer;
if((integer >= 5000) || (integer <=0))
{
cout << endl << "Invalid Integer" << endl;
}
else
{

if(integer >=1000)

piece = (integer / 1000);
for(int i = 0; i < piece; i++)
{
roman += "M";
}
integer%= 1000;
}

if( integer >= 100)
{
piece =(integer / 100);
if( piece ==9)
{
roman += "CM";
}
else if (piece >= 5)
{
roman += "D";

for( int i = 0; i < piece-5; i++)
{
roman += "C";
}
}
else if ( piece == 4)
{
roman += "CD";
}
else if (piece >1)
{
for( int i= 0; i < piece; i++)
{
roman += "C";
}
}
integer %= 100;
}
if ( integer >= 10)
{
piece = (integer / 10);
if ( piece ==9)
{
roman += "XC";
}
else if( piece >= 5)
{
roman += "L";
for( int i = 0; i < piece-5; i++)
{
roman += "X";
}
}
else if ( piece == 4)
{
roman += "XL";
}
else if ( piece >= 1)
{
for( int i = 0; i < piece; i++)
{
roman += "X";
}
}
integer %= 10;
}
if( integer >= 1)
{
piece = integer;

if( piece == 9)
{
roman += "IX";
}
else if( piece >=5)
{
roman += "V";
for( int i = 0; i < piece-5; i++)
{
roman += "I";
}
}
else if( piece ==4)
{
roman += "IV";
}
else if( piece >= 1)
{
for( int i = 0; i < piece; i++)
{
roman += "I";
}
}
}


cout << "Decimal" << "LongRoman" << "ShortRoman" << endl;



system ("pause");
return 0;
}

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Memory & arrays - Storing Roman Numerals into Arrays


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap