C++ :: Converting Numbers Into Words

Mar 13, 2014

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.

#include <iostream>
#include <cmath>
#include <fstream>
#include <cstdlib>
#include <iomanip>
using namespace std;

int main() {
ifstream in_stream;

[Code] ....

View 2 Replies


ADVERTISEMENT

C :: Converting To Lowercase And Counting Words

Apr 12, 2014

I am writing a program when the beginning it you have to pick which step to preform out of a few steps. Once you choose the step. The user is asked to input what is asked and it should preform it. I have completed most of my steps but the one step giving me a hard time is converting a user inputed sentence into all lowercase letters, and then count the words of it. My program starts out like this if you pick this step Code: else

if (choice == 3) {
/* Gather user's input */
printf("
You have chosen to convert a sentence to all lowercase letters and count the words
"
"Enter the sentence: ");
gets ( sentence );

Call the function to convert the whole sentence to lowercase and count the number of words */

lowercase_string ( &sentence);
countSentence ( &sentence);
} /* End if statement */

this is the easy part in which I presume I did correctly, but now this is where I am getting the problems:

/* Prompts user to enter a sentence and convert it to lowercase and count the number of words */

void
countSentence (char *sentence)
void
lowercase_string (char*)
{
[code]....

I want to output the original sentence, then the sentence with all lower case letters, then at last output the number of words in the sentence. I declared all my variables up top, and I am wondering where my mistake is. When trying to compile it, I only get syntax errors which I don't understand.

View 8 Replies View Related

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;

[Code] .....

View 7 Replies View Related

C/C++ :: Use Words Instead Of Numbers?

Sep 26, 2014

for (Initializing; Boolean_Expression; Update) i'm tying to use the words instead of numbers to repeats ,already i changed( Initializing; Boolean_Expression and Update) it doesn't work ,all i got is just Numbers !!

# include <stdio.h>
main()
{

[Code]....

View 3 Replies View Related

C++ :: How To Convert Numbers Into Words

Apr 29, 2014

How to convert numbers into words using ragged dynamic arrays? this is my solution:

int main()
{
char *Units[]={"ZERO", "ONE", "TWO", "THREE","FOUR","FIVE", "SIX","SEVEN", "EIGHT", "NINE"};
char *teens []={"TEN", "ELEVEN", "TWELVE","THIRTEEN", "FOURTEEN", "FIFTEEN", "SIXTEEN", "SEVENTEEN", "EIGHTEEN","NINETEEN" };
char *hundreds []= {"HUNDRED"};
char *tens []={ "ZERO", "TEN", "TWENTY", "THIRTY", "FOURTY", "FIFTY", "SIXTY", "SEVENTY", "EIGHTY", "NINETY"};
char *currency []={"Dollars"};

[code]....

View 2 Replies View Related

C++ :: Convert Int Numbers To Words

Apr 29, 2014

Write a c++program that asks the user to enter positive integer numbers without points between 0 and 999. Then check the amount and print in words. You need to use dynamic ragged arrays..

This is my solution but I'm not sure if this is the right way for dynamic ragged array???:

int main()
{
char *Units[]={"ZERO", "ONE", "TWO", "THREE","FOUR","FIVE", "SIX","SEVEN", "EIGHT", "NINE"};
char *teens []={"TEN", "ELEVEN", "TWELVE","THIRTEEN", "FOURTEEN", "FIFTEEN", "SIXTEEN", "SEVENTEEN", "EIGHTEEN","NINETEEN" };
char *hundreds []= {"HUNDRED"};
char *tens []={ "ZERO", "TEN", "TWENTY", "THIRTY", "FOURTY", "FIFTY", "SIXTY", "SEVENTY", "EIGHTY", "NINETY"};

[Code].....

View 1 Replies View Related

C :: Scanning A File With Words And Int / Float Numbers

Dec 1, 2013

scanning a file with both words and INT's/Float numbers. This is the file data here.

15 25 200
3 10
17.99 22.99 109.99
100 2 4
5.99 99.99 20.00 49.99
10 10 10 10 10 10 10 10 10 10
3.99 5.99 7.99 8.00 5.00 5.00 5.00 6.00 7.00 9.99

[Code]...

What I'm focused on is reading in the first three numbers which I already have with fscanf and then reading in BUY TICKET with the digit afterwards. My problem is that I don't know how to reach that part of the file without scanning in something I don't want to. Also, how would I scan the number after scanning BUY TICKET? Would it be something like using %s and %d right afterwards?

View 4 Replies View Related

C++ :: Program To Return English Words For Numbers

Jan 13, 2014

i need a program which can convert numbers you enter into their respective words till 1 million.

View 19 Replies View Related

C/C++ :: Read In String With Multiple Words And Numbers?

Jul 23, 2014

I am trying to read user input for recipe ingredients which must include a ingredient name, and may include a quantity and a unit. Example: Stone ground flour 2 cups or Sugar 1 Tbsp or Milk. The problem I am having is that the string gets cut off after a space when multiple words are used for the ingredient name.

cin.ignore();
string line;
getline(cin, line);
istringstream record(line);
string name;
string name2;
int quantity = 0;
string unit;
record>>name>>quantity>>unit;

View 1 Replies View Related

C++ :: Converting Numbers Into Text

Jul 25, 2012

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.

View 12 Replies View Related

C++ :: How To Make A Program That Converts Input Numbers Into Equivalent Words

Nov 16, 2013

I've reached a point in "Jumping into C++" where I need to make a program that converts input numbers into their word equivalent.

So far I've made it work for numbers 0-9999. I've tried implementing 10000-99999 but there are problems with the order of the words printed (57865 would print fifty thousand seven thousand eight hundred sixty five). But besides that, the program is absolutely enormous (for me) and I'm wondering if it can be shortened. Keep in mind I can only use loops and if statements so far. Here it is:

Code:

#include <iostream>
#include <string>
void extras(int e);
void digits(int x);
void tens(int xx);
void hundreds(int xxx);
void thousands(int xxxx);
//void tens_of_thousands(long xxxxx);

[Code]....

View 6 Replies View Related

C++ :: Count Numbers Of Words In A Sentence Simply By Counting Spaces

Jan 22, 2014

I wrote a code that counts numbers of words in a sentence, simply by counting spaces... but instead of showing a true number it shows a wrong number.

#include <iostream.h>
#include <conio.h>
int check(char eh[10000]) {
int he=0;
for (int i=0; i<=10000 ;i++) {

[Code] ....

View 8 Replies View Related

C :: Converting Random Numbers Into Chars?

Apr 3, 2013

I am having difficulty completing 7th last line below I marked the line with an arrow.

Code:
int main(void) {
int MaxNum, /*number of random nos to generate */
i, /*index */
value,

[Code].....

View 4 Replies View Related

C :: Converting Number To Two 4bit Numbers

Aug 14, 2013

Example: If i had the number 5 it needs to be represented/stored as two 4-bit binary numbers,

so 0000 0101, = 0 5.
Or 22 = 0010 0010 = 2 2.

The initial numbers/values are being read from a binary file in to an array....

View 7 Replies View Related

C++ :: Converting Binary Numbers Into Decimal

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

C/C++ :: Converting Letters To Numbers In A Loop

Jan 25, 2014

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++)

[Code] .....

View 14 Replies View Related

C++ :: Import A File Containing Words And Numbers To Linked List - Bubble Sorting

Feb 16, 2013

I have a code able to import a file containing words and numbers to a linked list, but I also need to sort this linked list alphabetically. I've done research on this involving bubble sorting, but no explanationcan achieve this objective.

Below is the code that can only put the file into linked list:

Code:
#include<iostream>
#include<conio.h>
#include"U:C++WordClass2WordClass2WordClass.cpp"
#include<fstream>
#include<vector>
#include<string>
using namespace std;

[Code] .....

View 5 Replies View Related

C++ :: Converting Characters To Numbers Using Data Files

Feb 20, 2013

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)

[code]....

View 1 Replies View Related

C++ :: Count Number Of Words And Lines Then Print All Words

Dec 20, 2013

I have written below program to count number of words and lines and print the all the words.

#include <iostream>
using namespace std;
#include<fstream>
#include<string.h>
int main() {
ofstream outfile;

[Code] .....

Its compiling fine but when executed its displaying I infinite times...

View 3 Replies View Related

C++ :: How To Pick One Of Words Randomly From Text Instead Of Using All Words In It

May 19, 2013

I was reading this earlier [URL] ..... and I was trying to figure out how to pick one of the words randomly from my text instead of using all the words in it.

View 4 Replies View Related

C :: How To Print All The Words In A Trie

Mar 6, 2015

I am creating a trie (not a tree but a trie). I have the following structure:

Code:
struct tnode {
bool is_word;
list *children;
};
struct trie {
int length;
struct tnode *first;
};

list *children is a linked list that contain pointers to tnodes. For example: I have a trie with the words cup and cut:

c
u
/
p t

Given the example above you have the following linked lists:

1. [c] that contains a pointer to linked list 2.

2. [u] that contains a pointer to linked list 3.

3. [p, t]

Now I want to print the trie like:

cut
cup

View 2 Replies View Related

C :: Reversing String Not Words

Oct 2, 2014

I am trying to write a program in C to reverse a string .

Example - This is America
output - America is This

I have thought of two ways of doing this question

1) using 2D arrays ( no pointer)
2) Using Strings and pointer

Code:
#include<stdio.h>
#include<string.h>
main()
}

[code]....

View 4 Replies View Related

C :: Sorting Words Alphabetically

Dec 10, 2014

I've tried searching for answers around the web but everyone is using syntax that We haven't been taught before in class yet. I understand that the string library is probably the most efficient way of doing this but is there a way without using that library? Like using if, for, while etc. instead?

I've been told that using anything else other than the string syntax is far to complex but I think the more complex it is the more I will understand it.

View 9 Replies View Related

C :: Scrambling Words In Array?

Sep 3, 2013

I'm writing a function that scrambles(shuffles) words(strings) in a 2D array. The problem I'm having is that it is scrambing the characters. Not the actual words. I've used trial and error but I can't find what wrong.

Code:
void Scramble( char dest[208][13]) {
for (int i = 0 ; i < 108 ; i++) {
for (int j = 0 ; j < 2 ; j++) {
int m = rand() % 108;
int n = rand() % 4;

[Code] ....

View 2 Replies View Related

C :: Print Words Of A String

Dec 4, 2013

I want to print the words of a sentence, given as a string..But I have a problem with the end of the sentence, and cannot find the bug....

Code:

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
char str[80]="This is a sentence";
int main(){
}

[code].....

View 7 Replies View Related

C++ :: Cannot Search Words From Input

Apr 14, 2013

i am trying to create a c++ program that asks for an input and determines if it is a question or not by searching each word from the input across a database (txtfile)..so far I have managed to make it search the database for the word but it only works on one word.... i would like to be able for it to search every word on the input separatly..here is the code:

#include <cstdlib>
#include <cmath>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

[code]....

View 4 Replies View Related







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