C :: Convert Roman Numerals Into Decimal Numbers
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
ADVERTISEMENT
Nov 19, 2014
how to convert integers -> Roman Numerals using both if & switch statement.
View 3 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
Nov 11, 2013
this program is supposed to turn Arabic Numbers into Roman Numerals, but after making the program shown below I only am able to get some alt codes to show up (I got a green lantern symbol to show up)
How would I fix this program to show Roman numerals?
#include <iostream>
#include <climits>
#include <cctype>
using namespace std;
int main(void)//makes all values void until entered {
system("color 0C");
while(true)
[code]....
View 1 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
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
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
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
Mar 27, 2013
The code should convert binary numbers to decimal but it doesn't..
Code:
#include <stdio.h>
#include <math.h>
#include <string.h>
int main()
{
[Code] ....
View 4 Replies
View Related
Sep 23, 2014
I am trying to make a program that will convert a list of binary numbers from a file into decimal and print the decimal to the screen. I have no problem doing the conversion, the problem comes up when our teacher wants the input file in a format as such:
3
10110101
11111111
10101010
The first number is supposed to tell the program how many different 8bit strings it is going to have to convert, and then the following lines are those binary numbers.
I am not very experienced with file inputs, and I know how to open files and read lines in.. The problem is, how to say "ok the first line says 3, so now I have to convert the next 3 lines" . I am assuming it is just a simple loop that I am missing....
View 4 Replies
View Related
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
Mar 27, 2014
How would you go about converting a decimal value to hex and then do math? Every example of converting decimal to hex that I have seen creates an array and I wouldn't be able to do math if I did that. Something like this.
15 decimal to hex F
17 decimal to hex 11
F hex + 11 hex = 20
View 8 Replies
View Related
Jun 20, 2013
User enters sentence "The Smiths have two daughters, three sons, two cats and one dog." (The numbers may change depending on what the user chooses to enter. He told us the range would be from zero to nine.) and we have to convert the written numbers within the sentence into actual decimal numbers and print out the new sentence. Ex. The Smiths have 2 daughters, 3 sons...etc.
I have written the following bit of code which reads the string and finds all the "written numbers" but I am not sure how to proceed from there. I am stuck on how to print out the new sentence with the converted numbers as my professor mentioned something about creating the new string using dynamic memory allocation.
Code:
#include <stdio.h>#include <string.h>
int main () {
char A[100];
int length = 0;
int i;
[Code] .....
View 7 Replies
View Related
Dec 7, 2014
I had an exercise to convert from decimal to binary with base 2, it was simple simple i did the following:
Code:
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
void Conversion (int n);
[Code] .....
I then had an follow up exercise which was to replicate but for any base up to 10, i thought i would just have to replace 2 with a variable obtained from the user, however this did not work as i got an error saying too few arguments function but i cannot see why i am getting this.
Code:
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
float Conversion (int n, int b);
[Code] ......
View 5 Replies
View Related
Nov 15, 2013
The goal of my program is to convert a decmial number to a binary number.First, the program gets an input to an array of chars, and the function translate_dec_bin converts this array to a decimal number through the strtoul function.The problem is that my program prints the binary number with an additional "0".For exmaple, for the input 1 - the program prints 01 instead of 1, for the input 3 - the program prints 011 instead of 11.
Code:
#include <stdio.h>
#include <stdlib.h>
#define MAX_LEN 20
void translate_dec_bin(char s[]){
char st[sizeof(unsigned)*20] = { 0 };
}
[code]....
View 2 Replies
View Related
Jul 11, 2014
What is the difference between the two functions below? I created the function in the top and my friend created the function in the bottom. I just want to know why the function with the while loop prints the binary numbers backwards. And the recursive function prints the binary numbers correctly.
void findBinary(int num) {
int remainder = 0;
while ( num > 0) {
remainder = num % 2;
cout << remainder;
num = num / 2;
[Code] .....
View 3 Replies
View Related
Jun 14, 2014
I have written this function.
void intToBase(unsigned int val,char *buff, unsigned int base) {
int digit = val%base;
if(val == 0)
return;
intToBase((val / base), buff + 1, base);
if(digit >= 0 && digit <= 9)
*buff = (digit + '0');
if(digit >= 10 && digit <= 15)
*buff = (digit + 'A' - 10);
}
This function is suppose to convert a decimal number (val) to any other base number and put it into a string (buff).
But the function puts the value in a opposite way, like if the answer is suppose to be "123" i get this "321".
Note: the function must be recursive and i can't use loops.
View 1 Replies
View Related
Dec 24, 2014
This was an exercise from a book (convert a character string into a floating point value). It seems to work with both negative and positive decimal numbers.
It basically get each digit from the string multiplies by 10 to hold the place, and then adds the next to the result, if that makes sense.
Then determines where the decimal and null character are to figure out what to multiply by (1/1000 or whatever) to determine where the decimal should go. The variable names dealing with this part of the program aren't accurate names right now.
My question is, the output, is always putting 6 zero's. So if the argument is .95, Ideally the output should say .95 and not .950000, even though the value is still correct.
I know there the %.2f to determine the amount of decimals, but the amount of decimals in these instances would be varying depending on the argument sent to the function.
So, if 600.158 was sent as an argument, only 3 decimals would be displayed, as opposed to two from the previous example. Is there a way to do this?
Code:
// Function to convert a string to an integer
#include <stdio.h>
double strToFloat (const char string[])
[Code].....
View 7 Replies
View Related
Feb 8, 2014
I understand most of program below. Essentially, we have strings that we want to convert from hex values to decimal equivalents. We check if first two characters of string are 0x or 0X, which signifies hex format. If our hex string consists of solely digits like 0x25, then the processing is simple. We take the digit assign it to answer variable, and for each additional position in the hex base-16 system, we multiply the digit by 16.
Now if the hex string is something like 0x2A, then for 'A', the hexalpha_to_int() function is called, since we are able to find 'A' in the hexalpha string, we take the value of 'A', which is ascii 65 divide it by 2 and add 10 to it: 65/2+10=42.5. This doesn't make sense. What is the purpose of this logic right here: 10 + (i / 2).
Code:
#include <stdio.h>
#include <stdlib.h>
int hexalpha_to_int(int c){
char hexalpha[] = "aAbBcCdDeEfF";
[Code] ....
View 1 Replies
View Related
Mar 27, 2013
I nead to write a program that convert an octal number to decimal number, I thought I did it right but it doesn't work.. I have to use in the first for loop as it is because it is part of the instructions (student homework).
#include <iostream>
#include <math.h>
using namespace std;
void main() {
double numOfDig, num, newNum;
[Code] ....
View 1 Replies
View Related
Apr 16, 2014
I want to convert a decimal number to binary and store it in a string so that I can use that binary output for later computation. Here is what I did
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main()
[Code] ....
Now as you can see that all the binary output is in a[] but how do I get it into a string so that I can use something like printf("%s",string) and get the binary output ?
View 7 Replies
View Related
Feb 26, 2013
I'm trying to pass a decimal number to a function and convert it to binary and return it and print it out in main. But it prints out 1011 and then seg faults...not sure where it's tripping up
Code: int main(){
char* binNum = decToBin(25);
int i = 0;
while(binNum != NULL){
[Code].....
View 6 Replies
View Related
Sep 18, 2012
I tried to convert byte array with hex to equivalent decimal value as follows but it gives me unexpected results:
byte hex_arr[] = { 0x00, 0x01, 0xab, 0x90};
unsigned long i=0;
i = hex_arr[3] + (hex_arr[2] << 8) + (hex_arr[1] << 16) + (hex_arr[0] << 24);
the output is 4294945680
Correct output should be 109456
but when I try with byte hex_arr[]={0x00,0x00,0x0f,0xff};
it gives correct out put 4095
the correct output works until the hex values is {0x00,0x00,0x7f,0xff}
View 8 Replies
View Related
Feb 11, 2013
My program needs to be adjusted to send out the numbers as 2 decimal , but nothing work.
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int
number_ofstyle_American,
number_ofstyle_Modern,
[Code] .....
View 1 Replies
View Related
May 16, 2014
Extracting integers from a string is trivial, but I am unable to find a function or code that will extract decimal numbers from a string.
I have a string that looks something like this:
" Asdf 1 1.3825 4.0000 12.0000 1.9133 0.1853 0.9000 1.1359 4.0000 "
Any tips on extracting the numbers (in decimal form) and storing them in a vector?
View 5 Replies
View Related
Apr 25, 2014
This is the question: [URL] .....
Now I have the binary numbers printed out in my code, but I don't know how I can covert them into to decimal.
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
int main() {
int numberOfDigits;
int numberOfRows;
char flag;
[Code] ....
View 1 Replies
View Related