C :: Finding Written Numbers In A String And Converting Them To Decimal Numbers
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;
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;
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.
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
I need to display 0-15 hex numbers[0X00-0x0F] in decimal value...& I'm getting the output but it's not exactly what it should be,below is my code.. [This not the complete code,but main part where the changes are done]
Actual output i should get is for 1v it should generate 0001,for 2v it should generate 0010 and simultaneously till [15v-1111]... But what i'm getting is exactly different to this for eg for 7v,8v&9v the bits generated are 1101,1011,1011 respectively...
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
Create a program that will ask the user to enter a decimal value (1-999999) then display its corresponding binary numbers. Repeat this process until the value entered is equal to 0. Use the following Function Prototype:
void BinCodes(int value); Sample Input/Output: Enter a Decimal: 35 Binary: 100011 Enter a Decimal: 184 Binary: 10111000 Enter a Decimal: 0
I know how to write the GCD for one, two, three, four, and etc, numbers. But I cannot seem to find a way to write a code that does it for 'n' numbers.
That is, the user inputs a number 'n', which determines the size of a dynamic array. Then they are prompted to input the values for each of the elements in the array that will constitute the numbers the program is to find the GCD for.
This records the array:
for (int count = 0; count < n; count++) { cout <<"Enter the numbers you wish to find the GCD for, for term" << count << ": "; cin >> GCD_n[count]; }
Here is a code for finding GCD of three numbers:
cout << "This program finds the greatest common divisor of three numbers. " << "Enter the first number: "; cin >> a;
[Code] ....
How to proceed coding a program that finds the GCD of 'n' terms.
GCD_n[n] is the array that contains the numbers for which we need to determine the GCD for.
My main problem is with writing a code that tests the elements of the array containing the list of numbers in GCD_n[n], all at the same time, such that:
int n; cout << "This program finds the greatest common divisor of n numbers. " << "What is the total amount of numbers you want to find the GCD for?
I am trying to read into a file that has something like
I have 5 apples and 9 bananas. Sam has 8 apples and 6 bananas.
and I need to replace the numbers with words. For example I need to change the "5" to five and so on. The problem is that im not sure how to access and then replace just the numbers.
Take a number that is entered by a user and turn that into printed text. Ex. 85 would be eight five. The problem I am having is I'm not quite sure how to go about this. I don't know if I should use an array, string, or something else.
My question is to write a complete program that will search a file of numbers(numbers.txt) for the smallest and largest numbers and then write the values to the screen using a single pass through the file. File only contains type int and holds at least one int. My questions are am I reading in the first number correctly? Where would I read in the second number to compare to the current max and min?
Code:
#include <stdio.h> #include <stdlib.h> int main(int argc, char * argv[]) { FILE *fin; fin = fopen("numbers.txt", "r"); //check to make sure file opened if(fin == NULL) }
Ok so I'm reading the Programming: Principles and Practice using C++ and Im stuck in Drill 4 part 5. It says:
Change the program so that it writes out the "numbers are almost equal" after writing out which is the larger and the smaller if the two numbers differ by less than 1.0/10000000
I'm using an If statement for it... I just need know what the formula is to check 2 numbers that were entered by person if they land within the range specified above. so then I can cout << "numbers are almost equal" << endl;
I have my program working, as far as converting the letters to numbers, but i want be able to enter as many numbers as i want. so i figured i could put into a loop asking a question at the end. question being whether the user wants to enter another number or not. also i'm assuming the user enters exactly 7 letters each time. this is my code so far.
const int arSize = 9; char letters[arSize]; int numbers[arSize]; int count = 0; cout << "Enter a telephone number expressed in letters. (e.g. CALL loan ( it is not case sensetive))"; for (int i = 0; i < 7; i++,count++)
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....
I have written a program that finds the divisers of non-prime numbers and outputs them. However, the output is only one diviser per line(because of the repetition to find the divbisers), but the instructor wants us to have 5 to 10 divisers per line. How can i write this loop so it will only output the divisers in one line?
A prime number is a number greater than 1 which is only evenly divisible by 1 and itself. For this assignment you will find which numbers from 2 to n (where n is a user-specified number) are prime. Ask the user for a number, n, greater than 2. Keep asking for a number until a number greater than 2 is provided. Assume that the user will only enter numbers (that is, you do not need to check if a user enters text).
Use a loop to iterate on a variable, i, from 2 through n. For each iteration, check all numbers from 2 through i to determine whether the number is prime. If it is prime, print out i and the word "Prime". Use the modulus operator, %, to determine if a number is prime
Example output:
Please enter a number larger than two: -939 Please enter a number larger than two: 2 Please enter a number larger than two: 20 2 Prime 3 Prime 5 Prime 7 Prime 11 Prime 13 Prime 17 Prime 19 Prime
This is what I have so far. I suppose i'm not really understanding how to continue with the second for loop. The first one just prints out a list of numbers from 2 to the number designated by the user. In my case that variable is user_input.
I'm currently working on an assignment that finds all happy numbers for a given range. Such as 1- 10. My current code just isn't cutting it. I have to use a user defined function and return a bool value to main in order to output if the number is happy or if it sad. For some reason, I cannot get it to loop properly. the first number will be displayed correctly, but the second and third are just squares of the first number, instead of being squared by their single digits. I'm dividing by 10 to get the first number of the digit entered, then I'm using mod to get the remainder. One thing I did notice was that the num2 was putting a remainder of 30 for 130, and I'm not too sure what I need to do to change that, without affecting the whole program.
#include <iostream> #include <iomanip> #include <cmath> #include <cctype> #include <string> #include <cstdlib> using namespace std; Program calculates the bill for a user
I need to convert characters in a input file to numbers in output file and display both the characters and numbers in a console window.Only 7 numbers can be displayed, the rest needs to be dropped.The input file contains the following data, with one number per line:
CALL HOME GET LOAN Hi THERE BYE FOR NOW
For example, once the first number in the input file has been processed, the console window should display the following: CALL HOME 225 5466.
The output file should now also contain the number: 225 5466
Currently my console is displaying the following:
Enter the input file name. infile.txt
Enter the output file name.
outfile.txt 2554663Invalid Input 4385626Invalid Input 4Invalid Input 84373Invalid Input 293367669Invalid Input 4357637277CALL HOME GET LOAN Hi THERE BYE FOR NOW
#include <iostream> // for screen/keyboard i/o #include <fstream> // for file #include <cstdlib> // for exit using namespace std; void openFile(ifstream& infile)
Write a program that prompts the user to enter a number larger than 2. The program should use the Number class to determine the prime numbers between 2 and the number entered, and display them in the console window.I've been stuck for a while now and just lost in implementing classes and contstructors.
#include <iostream> using namespace std; int main(int argc, char * argv[]) { cout << "Enter a number larger than 2: " << endl; int n; cin >> n;