C/C++ :: Convert Decimal Number To Roman?

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


ADVERTISEMENT

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 View Related

C++ :: Convert 8-digit Binary Number To Decimal Number?

Jul 6, 2013

Code: Complete the program below which converts a binary number into a decimal number. Sample outputs are shown belowComplete the program below which converts a binary number into a decimal number. Sample outputs are shown below.

Sample Output 1:

8-bit Binary Number => 11111111
Decimal Number = 255

Sample Output 2:

8-bit Binary Number => 10101010
Decimal Number = 170

Sample Output 3:

8-bit Binary Number => 101010102
Number entered is not a binary number

#include <iostream>
using namespace std;
int main()
{
int num;

[code]....

View 2 Replies View Related

C++ :: Convert Binary Number Into A Decimal Number

Jul 5, 2013

Here's the part of the codes where I tried to use boolean expression:

Code:
#include <iostream>
using namespace std;
int main() {
int num;
cout << "8-bit Binary Number=";
cin >> num;

[Code] .....

How can I get started with the body?

View 7 Replies View Related

C++ :: Convert Binary Number Into Decimal Number?

Jul 5, 2013

Here's the part of the codes where I tried to use boolean expression:

#include <iostream>
using namespace std;
int main()

[Code].....

May I know that how can I get started with the body?

View 5 Replies View Related

C++ :: Program To Convert Octal Number To Decimal

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

C :: Convert Decimal Number To Binary And Store It In A String

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

C :: Pass Decimal Number To Function And Convert It To Binary?

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

C/C++ :: How To Convert Byte Array With Hex Number To Equivalent Decimal Value

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

Visual C++ :: Roman Numeral Converter To Decimal Using Array Of Strings

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

C :: Convert Integers To Roman Numerals?

Nov 19, 2014

how to convert integers -> Roman Numerals using both if & switch statement.

View 3 Replies View Related

C/C++ :: Convert Integers To Roman Numerals

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

C :: Convert Roman Numeral Inputs To Normal Numbers?

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

C++ :: Calculator To Gives Result Of Roman Numerals In Roman Mode

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

C/C++ :: How To Convert A Decimal Value To Hex

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

C++ :: Convert From Decimal To Binary With Base 2

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

C :: Convert Binary Numbers To Decimal

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

C :: Convert Decimal To Binary On Language

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

C++ :: Function To Convert Decimal To Binary

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

C/C++ :: Convert Decimal To Another Base And Put It Into String

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

C :: Function To Convert String To Floating Decimal

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

C :: Convert Strings From Hex Values To Decimal Equivalents

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

C++ :: Input Decimal Number And Output To Be Number Scientific Notation

Apr 26, 2013

I need to write a code in c++ , to input decimal number and the output to be number in Scientific notation with 32 bits .

View 1 Replies View Related

C++ :: Convert List Of Binary Numbers From A File Into Decimal And Print To Screen

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

C :: Binary Number To Decimal

Mar 30, 2014

I am very new to programming and have been working on a program that can receive decimals or binary numbers and convert them. The decimal --> binary works fine. For some reason I cannot figure out I cannot get the "BinaryToDecimal" function to perform. By putting a "printf" into the for-loop.

Code:

#include <stdio.h>#include <string.h>
#include <math.h>
char* ReverseString (char _result[]) {
int start, end, length = strlen(_result);
char swap;
for (start = 0, end = length-1; start < end; start++, end--)

[code]....

View 2 Replies View Related

C/C++ :: Binary Number Into Decimal?

Sep 10, 2014

I have a code and am asked to modify it so that it will take as input as unsigned binary number up to 16 digits in length and convert it into its equivalent decimal number and output that decimal number.

All I know is that I use library function strlen() in <cstring> to calculate the length of the input string.

I also know I have to use something called pow(2,4);

//pow (); is found in cmath

I was told to use sum = sum >>16-l; (l is the length of />/>

#include <iostream>
using namespace std;
int main() {

[Code]....

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved