C/C++ :: Roman Numeral Converter?
Dec 23, 2013
I am writing a program that converts arabic numbers into roman numerals.
Quote Write a program that asks the user to enter a number within the range of 1 through 10. Use a switch statement to display the Roman numeral version of that number.
Input Validation: Do not accept a number less than 1 or greater than 10.
Prompts And Output Labels. Use the following prompt for input: "Enter a number (1 - 10): ". The output of the program should be of the form "The Roman numeral version of A is R" where A is the Arabic numeral entered (1,2,3,...) and R is the all-capitals form of a Roman numeral, such as VII.
View 14 Replies
ADVERTISEMENT
Jun 27, 2013
This program compiles, but has a bunch of logical errors. I know my problem is somewhere in the while loop that I have, but I can't figure out where. Here are some of the issues I am experiencing:
1. At the beginning of the program it asks you to enter a number, and when you do it does nothing while proceeding to the while loop where I have it asking the same question
Code:
"Please enter a number between 1 and 20 (Enter 0 to stop)
";
cin >> num;
cout << endl;
I want to be able to eliminate that first statement but if I only run this in the loop without the above statement the program will display nothing on the screen and proceeds to stop.
2. This code runs fine, except that if you make a mistake, it will prompt you to enter a valid number, however; it ignores your first response if the number you enter is valid and asks you to enter a valid number anyway. Once you enter it a second time, it will accept it and the program will continue on.
Code:
while(num != SENTINEL) {
cout << "Please enter a number between 1 and 20 (Enter 0 to stop) ";
cin >> num;
cout << endl;
Also if you type in 0 on your first response, it will prompt you that it is not a valid number and ask you to try again, instead of stopping the program like it is supposed to do. On your second response the program will accept your 0 and stop the program correctly.
//Write a program that displays the roman numeral equivalent of any decimal number between 1 and 20 that the user enters. The roman numerals should be stored in an array of strings and the decimal number that the user enters should be used to locate the array element holding the roman numeral equivalent. The program should have a loop that allows the user to continue entering numbers until an end sentinel of 0 is entered.
Input validation: Do not accept scores less than 0 or greater than 20
#include <iostream>
#include <string>
using namespace std;
int main() {
// Declare constants and variables
const int romanNum = 21; // Size of the elements in the array
[Code] ....
View 14 Replies
View Related
Aug 31, 2014
Here is the problem:"Write a program that converts a number entered in Roman numerals to a positive integer. Your program should consist of a class, say, romanType. An object of type romanType should do the following:
a. Store the number as a positive integer.
b. Convert and store the number as a positive integer.
c. Print the number as a Roman numeral or positive integer as requested by the user.
The integer values of the Roman numerals are:
M 1000
D 500
C 100
L 50
X 10
V 5
I 1
d. Test your program using the following Roman numerals: MCXIV, CCCLIX, MDCLXVI."I'm doing the best I can to understand the concept of the class. Here is what I have (which is not much thus far, and nowhere near correct I'm sure).
#include<iostream>
#include<iomanip>
using namespace std;
class romanType {
public:
void getRoman();
[code]....
View 19 Replies
View Related
May 4, 2014
I have a fascination with Roman numerals and would like to create a C program that converts Roman numeral inputs to normal numbers.
I want to keep everything simple and only use the C library for the coding.
View 4 Replies
View Related
Dec 5, 2013
About exercise 7 of chapter 10 of PPP (page 372): changing the calculator to gives us the result of the roman numerals, like XXI + CIV = CXXV.
At *first* time there are two solutions for solving it in my mind.
First is, giving each roman number to a function like the one existing in exercise 6 and then get their integer numbers and then calculate them by the calculator of chapter 7 and finally make a function to convert the result to roman mode. (simpler)
Second is to change the calculator from chapter 7 to calculate roman numbers inside itself and gives the result again in roman mode. (harder)
As an important step of ‘solving the problems’/’programming’, how can I make decision to choose a solution for solving a problem.
View 8 Replies
View Related
Dec 20, 2013
Basically i am really close (i think) and the numbers im getting when i run it are weird like for instance i should get back a one if i enter in I or i but instead im getting like 178976087.
MAIN:
#include "stdafx.h"
#include "iostream"
#include <iomanip>
#include "romanType.h"
using namespace std;
int main() {
romanType r;
[Code] .....
View 5 Replies
View Related
Nov 19, 2014
how to convert integers -> Roman Numerals using both if & switch statement.
View 3 Replies
View Related
Feb 26, 2014
Program to convert a date entered into roman numerals. I can only use one output prompt to get the date, so that makes it more difficult. Here is what i have, but how to go about the rest of it.
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
int array_date[20];
char I; // one
[Code] .....
View 1 Replies
View Related
Sep 17, 2014
#include "stdio.h"
#include <stdarg.h>
#include <math.h>
// Main Function
int main(void){
int number;
printf(" Please enter a number from 1-10? ");
scanf("%d", &number);
[Code] ....
I took the while statement out didn't want that in there.
View 2 Replies
View Related
Mar 23, 2015
I've Been working on a program that acts as a form of Roman numeral calculator, I input Roman Numeral Characters, and the program (is suppose to) output the corresponding digits. *Not allowed to use for loops or arrays.
Input:
MCCXXVI
LXVIIII
+
Output:
The First number is 1226
The second number is 69
Arithmetic operation is +
the sum of 1226 and 69 is MCCLXXXXV (1295)
However, when I run the program:
input:
MCCXXVI
LXVIIII
+
Output:
The first number is 77
The second number is 76
Arithmetic Operation is +
The sum of 77 and 76 is (infinite loop of I's) (153)
I noticed that when I input MCCXXVI, it only takes the first character (I thought cin.get() was suppose to stop this?), and returns the ASCII decimal value of that, instead of the integer value that I assigned to each letter. Why i get an infinite loop, and how to fix it.
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
const int I_Value = 1;
const int V_Value = 5;
[Code] ....
View 14 Replies
View Related
Oct 11, 2013
So I am trying to write a program that converts roman numerals into decimal numbers. I so far have come up with:
Code:
#include <stdio.h>
#include <ctype.h> // importing the tolowerfunction
//variables
int decimal, total;
char numeral[];
[Code] .....
But each time I compile it, it times out as if it were hitting an infinite loop. I have a feeling that I am not passing an individual character to the roman_to_decimal function but am unsure why.
View 5 Replies
View Related
Feb 5, 2013
I know my current program will not compile. How can I store the the start temperature so it can be used again in the final printf statement "start degrees Fahrenheit is converted Celsius."?
Note - I want to use the float data type for precision.
Code:
//THIS PROGRAM WILL CONVERT TEMPERATURES BETWEEN DEGREES FAHRENHEIT AND DEGREES CELSIUS
#include <stdio.h>
int main(void)
[Code].....
View 4 Replies
View Related
Feb 26, 2013
I'm trying to make a program that takes up to a seven digit binary number and converts it to its decimal equivalent. I'm still a beginner, so this might be a simple question but how do I stop the user from entering anything but 1s and 0s? This means no decimals or numbers other than 1 or 0.I already made it so it won't accept anything below 0 or above 1111111.
View 1 Replies
View Related
Mar 15, 2013
#include <iostream>
#include <math.h>
using namespace std;
int main() {
int N=0, counter=0, counter1=0,counter2=0, temp=0, temp1=0,dec=0,result=0, moder=0;
[Code] .....
This is Binary to Decimal Converter. It's not working. Although Dry Run of this program works fine.
View 4 Replies
View Related
May 23, 2013
I wrote this code purely for educational purposes. It also learn more about how exactly things look in memory. code I have right now ( I will likely add more and change it in the future) .....
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
[Code].....
View 7 Replies
View Related
Sep 9, 2014
I was trying to program an decimal to binary converter (8-bits) in C. I am a complete beginner so I tried to put the 1's and 0's of the binary number as they come without reversing the order for beginning. I have seen example on the internet but didn't understand them so I decided to write it as I understood it. So, I typed the code as shown below:
Code:
#include <stdio.h>
#include <stdlib.h>
int main() {
int number;
int BitNum[8], x;
[Code] ....
The problem with the code is that if binary form has 0s in it then program displays a random number instead of a 0. For example if decimal is 7, it should print out 11100000 but it displays only 111(and some stupid numbers instead of 0). I have tried to solve it but failed.
View 7 Replies
View Related
May 28, 2014
One of the questions requires writing up a code, that converts Fahrenheit scale to Celsius scale.
The relation between temperature in ◦ C and ◦F is given by the formula:
◦C = 5/9 . ( ◦F - 32 )
Write a program that prints a table (just two columns without any borders) with temperature in ◦F and ◦C for temperatures between 0 and 300 ◦F in steps of 20◦. Compile and run your program. I wanted to approach this problem via arrays and for loops, and I wrote up this
Code:
#include<stdlib.h>
#include<stdio.h>
int main() {
// begin main()
// units
double[] celsius = new double[ 16 ];
double[] fahrenheit = new double[ 16 ];
[Code] ....
Now when I'm trying to compile that, the compailer throws an error which makes absolutely no sense to me.
Code:
fahrenheitCelsius.c: In function ‘main’:
fahrenheitCelsius.c:18:9: error: expected identifier or ‘(’ before ‘[’ token
double[] celsius = new double[ 16 ];
[Code] ....
View 7 Replies
View Related
Jun 12, 2014
I wrote a program that converts Binary code to Grey code. It works, but I feel like it's highly inefficient. I've also been trying out Project Euler, but I seem to always turn to using vectors whenever solving a problem.
/* Binary to Grey Code Converter */
#include <iostream>
#include <vector>
using namespace std;
// Global Variables (I'd like to not use them because I've been told it's bad practice)
static int numDigits;
int digit;
vector<int> bin;
[Code] .....
View 1 Replies
View Related
Sep 1, 2014
I need to convert a string into a Font object. I'm trying to use the Font Converter but I don't see support for the font Style. I need to save a font to a string and back again using the font name, size and style.
Font font1 = (Font) converter.ConvertFromString("Arial, 12pt");
View 1 Replies
View Related
Apr 8, 2015
I am attempting to reconfigure a working code that before used while loops and if statements to convert a numeric score to a letter grade. I now wish to take this same code however I want to change the char convertGrade(int numScore) to simply use a parallel array as a replacement to the if statements.
The array needs to consist of 3 arrays of fixed size 5:
int minScores[SIZE]
int maxScores[SIZE]
char letterGrade[SIZE]
I know the declarations need to go in the function convertGrade but this is the first time I have worked with arrays and I am having trouble trying to figure out how this array will replace my previous if statement.
In order to access the array elements I need to write specifications such as
minScores[i]
maxScores[i]
letterGrade[i]
(where i = 0, 1, 2, 3, or 4)
#include <stdio.h>
#include <stdlib.h>
#define SIZE 5
int getScore(void);
char convertGrade(int numScore);
[Code] .....
View 5 Replies
View Related
Sep 21, 2014
I recently wrote a program to convert numbers to binary in c++, Well here it is:
#include <iostream>
void recur(int convert) {
if(convert == 0) //if input is 0 , return nothing. {
return;
}
recur(convert/2); // divide convert by 2, get only a 1 or 0
[Code] ....
View 13 Replies
View Related
Apr 18, 2012
Basically I have 2 questions.
1. Because of how limited integers are in terms of storage, the largest binary number i can give seems to be 1 111 111 111. Anything larger breaks the program. Is there any way to increase the largest input I can give without completely rewriting the program? I tried changing the num/numCounter (and the typecasting) to long doubles, but it just messed stuff up (or I did).
2. I'd also like to make it so that if someone inputs a non-binary number my program tells them so and stops. I figured a switch statement within the while loop would work (for when numCounter/divisor is negative or greater than 1), but I was wondering if instead it was possible to use an if statement that could break the while loop?
Anyway, here's the code:
Code:
#include <QtCore/QCoreApplication>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
using namespace std;
int main(int argc, char *argv[]) {
QCoreApplication a(argc, argv);
[code]....
View 7 Replies
View Related
Oct 5, 2014
I'm trying to figure out why the binary to decimal part is not working correctly when the binary value finishes with a 1. In those cases, the decimal value shown in one unit smaller than it should be.
Code:
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
void Binary_to_Decimal(), Decimal_to_Binary(); //prototype for the 2 functions that contain the converters
int main() //the menu {
int a_Choice;
cout << "Enter 1 - for binary to decimal" << endl;
cout << "Enter 2 - for decimal to binary" << endl;
[code]....
View 2 Replies
View Related
Nov 26, 2013
I've been doing some practice programming challenges and I am currently making a temperature converter from Imperial to Metric.
My approach was to make it as simple as possible but it must display correctly and use decent I/O manipulations corresponding with how high the counter is.
This is what I have come up with, and everything seems to work fine for a base where I could possibly add more code to include user input, but before I go to that one step further I'd just like to know if the approaches I have taken to using iomanip is OK practice and I haven't done any serious no-nos, as I haven't seen any code from example videos that people make that includes this!
Here's the code:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
[Code] ....
The reason I added the IO manipulators is because I couldn't stand seeing everything not lining up, it looked very sloppy and unprofessional..
View 2 Replies
View Related
Dec 1, 2013
I have to create a converter but the results must be in 4 decimal places just like, if i Entered 5000mm the result would be 500.0000cm . what should I do ? I used Float function
View 1 Replies
View Related
Nov 13, 2014
I'm trying to make a simple temperature converter with a menu that lets users pick which conversion to perform. But, it won't seem to print the right conversion. It just prints the same temperature that I inputted.
for example:
#include <iostream>
using namespace std;
//prints the menu
void userMenu(){
cout << "Temperature Calculator" << endl << endl;
[Code] .....
View 2 Replies
View Related