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
ADVERTISEMENT
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
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
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
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
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 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
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
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
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
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
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
Aug 18, 2012
I've been working on making a class that makes turning any variable or object into a byte array and vice-versa, quick with minimal pointer interface.
As well as a function for turning any variable or object into a binary text string.
Code:
#include <iostream>
#include <bitset>
#include <sstream>
// Convert a Variable to a Byte Array
template <class var>
unsigned char* VarToBytes(var &data) {
[code].....
View 2 Replies
View Related
Oct 21, 2013
This code is near complete, the only task that is left is allowing the user to input a decimal and then two integers, or automatically using .00 decimal.
The automatic part: /*This is not correct.
printf(".%.2d
", number);
*/
But that does no good for me. Question: Do I have to create a some sort of while loop again, to allow the user to input a decimal followed by integer?
Code:
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
int j , i = 0, k = 0;
int number;
[code]....
View 1 Replies
View Related
Feb 21, 2015
I want the input for the price in decimal format(15.00). If the input is in integer format then I want to convert it to decimal format.
The maximum price for a sale is 999.99 and minimum is 0.00.
I have tried so far:
Code:
#include<iostream>
using std::cout;
using std::cin;
void main(){
float eventPrice;
[Code] .....
A valid input will be:
1.8,
0.8,
0.00,
0,
9,
99
View 2 Replies
View Related
Dec 19, 2014
Write a C++ program that adds three binary numbers of 8-bit each. Every number is stored into an array of 8 elements.
Example:
Array A
0 1 2 3 4 5 6 7
0 1 1 0 1 1 1 0
+
Array B
0 1 2 3 4 5 6 7
0 1 1 0 1 1 1 0
+
Array C
0 1 2 3 4 5 6 7
0 1 1 0 1 1 1 0
Store the result into an array D of 8 elements. Your program should show the decimal numbers for every binary number. Print screen of 6 answers. This means you should try your program six times with different numbers in every run and show the printed screen result.
View 5 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
Sep 24, 2014
Write a program which stores 10 decimal numbers in an array. For these numbers accept input from the users. Once the array is populated do the following:
Display each elements of the array
Display the sum of all the elements of array
View 1 Replies
View Related
Sep 24, 2014
Write a program which stores 10 decimal numbers in an array. For these numbers accept input from the users. Once the array is populated do the followings:
Display each elements of the array
Display the sum of all the elements of array
View 4 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
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
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
Aug 19, 2013
I'm trying to make an application for ELM327 trouble code scanning device for my own educational purpose. Most of my app code is done. however, I am stuck at one point. And I need finding relationship between two hex strings.
I have logged some communication between ECU and a chinese code scanning device for carrying out car's fuel pressure test. However there is one message (that is sent from the user side) that keeps on changing each time which is dependent upon the last message received from the ECU which is also varying every time.
Code:
RECEIVED (07E8) SEND (07E0)
05 67 03 0C 17 6A 00 00 05 27 04 8F 45 37 00 00
05 67 03 0C DB 68 00 00 05 27 04 B0 70 6B 00 00
05 67 03 10 3B 87 00 00 05 27 04 3B BC 10 00 00
[code]....
as it can be seen 3 bytes are always changing with each test, both, in the message received from the ECU, and the one sent back to the ECU from the diagnostic scanner. Trying to figure out relationship between these two strings?
P.S: about 16 million combinations for 3 byte data are possible... there must be some link between them...
View 4 Replies
View Related