I have a good start

This is a discussion on I have a good start within the C++ Programming forums, part of the General Programming Boards category; I do apologize. Now that I posted it in C++ and not C (haha), I was wondering if I could ...

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    3

    I have a good start

    I do apologize. Now that I posted it in C++ and not C (haha), I was wondering if I could have a little help extending my program from 1-999(which works fine) to -1billion to 1billion. I technically am getting full credit on the project but I was hoping for extra credit to boost my B letter grade for my GPA.
    Would this involve more strings each for thousands, millions, and billions?
    Code:
    #include<iostream>
    #include<fstream>
    #include<stdlib.h>
    #include<cmath>
    #include <cstdlib>
    using namespace std;
    
    string sayones(int o)
    {
    	string sayones[] = {"","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};
    	return sayones[o];  
    }
    
    string saytens(int t)
    {
    	string s[] = {"","","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"};
    	return s[t]+" ";  
    }
    
    string sayhun(int n)
    {
    	return sayones(n)+" hundred ";;  
    }
    
    string saythree         
    
    int main()
    {
        int num;
        cout<<"please input 0-999: ";
        cin>>num;
        
        
        
        int h, t, o;
        h = num/100;
        t = (num-100*h)/10;
        o = num%10;
    	
    	if (num<=10||num<20){
    			string word_form1 = sayones(num-h*100);
    			cout<< word_form1 <<endl;
    		}
    			else {
    			if (num<=99){
    					string word_form3 = saytens(t)+ sayones(o);
    					cout<< word_form3 <<endl;
    				}
    				else {
    				if (num==0) {
    					cout<<"zero";
    				}
    
    					else {
    						if (t==1&&num>99){
    							string word_form2 = sayhun(h)+ sayones(num-h*100);
    							cout<< word_form2 <<endl;					}
    						else {
    							string word_form4 = sayhun(h)+ saytens(t)+ sayones(o);
    							cout << word_form4<<endl;
    					}
    
    				}
    			}
    }
    
    system("PAUSE");
    return 0;
    }
    Sorry if this isnt how it is supposed to look for posting it in code form. I am learning.

  2. #2
    Registered User
    Join Date
    Apr 2011
    Posts
    3
    Mostly I am looking for some advice on the billions part. I did well on the first part of te program and now I am turning to community help.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    123,123,123
    One hundred and twenty three million, one hundred and twenty three thousand, one hundred and twenty three.

    Once you've got the pattern for groups of 3 digits, it's pretty simple.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Apr 2011
    Posts
    3
    so you are saying making a fourth string, say sayfour which basically adds all the previous strings into it but change one word to thousand or million or billion instead?
    also how do you make the program "check" for a negative sign so it can cout the word negative?

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    I'm sure you'll figure something out if you think about it a bit longer.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,422
    Quote Originally Posted by projekt51 View Post
    ...also how do you make the program "check" for a negative sign so it can cout the word negative?
    This one is pretty easy. What is the mathematical condition for a number to be negative?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MFC: A good place to start?
    By Sentral in forum Windows Programming
    Replies: 7
    Last Post: 03-02-2006, 02:42 AM
  2. Game programming ........ Where is good place to start?
    By 3DPhreak in forum Game Programming
    Replies: 4
    Last Post: 06-17-2004, 10:54 AM
  3. Is this good enough to start with?
    By GTO in forum C++ Programming
    Replies: 5
    Last Post: 11-17-2001, 03:09 AM
  4. Where is a good place to start?!
    By bobthefish3 in forum Game Programming
    Replies: 1
    Last Post: 10-09-2001, 11:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21