Welcome to Tech Support Forum home to more then 136,000 problems solved. Issues have included: Spyware, Malware, Virus Issues, Windows, Microsoft, Linux, Networking, Security, Hardware, and Gaming Getting your problem solved is as easy as:
1. Registering for a free account
2. Asking your question
3. Receiving an answer

Registered members:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* See fewer ads.
* And much more..

 



Want to know how to post a question? click here Having problems with spyware and pop-ups? First Steps
Go Back   Tech Support Forum > Design Forum > Web Design & Programming
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read


Web Design & Programming Discussion of web design, and server-side & client-side scripting

Reply
 
LinkBack Thread Tools
Old 09-27-2008, 04:30 PM   #1 (permalink)
Registered User
 
darklordryu's Avatar
 
Join Date: Jul 2006
Location: Connecticut, US
Posts: 218
OS: Vista Desktop, XP Laptop

My System

Send a message via AIM to darklordryu
c++ help please -.-

here's the deal
I need to "design my program with a function that takes as an argument an integer between 0-99 and returns a string that contains the integer value in english. It shouldn't have 100 different id else statements, I'm supposed to use % and / to "extract the tens and ones digits to construct the english string"

all of this drama is to make a program that outputs the lyrics from "Ninety-nine bottles of beer on the wall"

I'm not looking for someone to write the code for me (although I wouldn't say no hah) what I am looking for though is someone who could mayhaps explain to me *** all that nonsense means

I have absolutely no idea where to start...I barely understand what a function is

in fact, I don't understand programming at all hah what I have so far is


#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

int beer (int number_par);
{


}
int main (void)

{
}

so basically...nothing. Any help would be appreciated cause like I said I don't even know where to THINK about beginning how to approach this

-.- thanks
__________________
"Health and long life are the gifts of the spice!"
darklordryu is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Important Information
Join the #1 Tech Support Forum Today - It's Totally Free!

TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free.

Join TechSupportforum.com Today - Click Here

Old 09-27-2008, 04:49 PM   #2 (permalink)
Design Team Member
 
jamiemac2005's Avatar
 
Join Date: Jul 2007
Location: Coventry, UK
Posts: 1,880
OS: Vista, various linux distros


Re: c++ help please -.-

Hey, this isn't too hard of a problem. You have the basic frame set out... though if beer() is the function you're talking about it should have a string datatype:
Code:
string beer(int number_par)
If you don't understand programming at all i suggest you try the tutorials here(for C++): http://www.cprogramming.com/

You have all the information you need to approach the problem...

Do you know the %(modulus) operator?

if not then basically 25/10 = 2.5(the division)(which could then be modulated by 1 to make .5 which could then be subtracted from the result)
whilst 25%10 = 5 (the remainder)

Using that knowledge you should be able to parse the digits from the number then you could use a switch-case statement to work out what that number is as a string

Cheers,
Jamey
__________________

Myspace
jamiemac2005 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 09-27-2008, 04:53 PM   #3 (permalink)
Registered User
 
darklordryu's Avatar
 
Join Date: Jul 2006
Location: Connecticut, US
Posts: 218
OS: Vista Desktop, XP Laptop

My System

Send a message via AIM to darklordryu
Re: c++ help please -.-

yeah beer was the name of the function...it's little things like that that I miss and don't even think about taht it should be a string and not an int...ack I hate this stuff hah

that...modulus thing dind't make sense to me at all -_-...I don't understand what you mean by 2.5 could be modulated to 1 to make .5

or what parsing digits is
or what a switch case statement is hah

but much thanks for the link, I'm defintiely gonna go check that out
__________________
"Health and long life are the gifts of the spice!"
darklordryu is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 09-27-2008, 07:12 PM   #4 (permalink)
Moderator: Design
 
dm01's Avatar
 
Join Date: Oct 2006
Location: Richmond, B.C.; Canada
Posts: 1,454
OS: Windows XP [Version 5.1.2600] SP3 | Ubuntu Jaunty Jackalope | Windows 7 BETA

My System

Re: c++ help please -.-

Modulus is just like division, except the remainder is stored in the variable address instead of the quotient. The rest of Jamey's post was gibberish to me as well.

There should be a way to loop this around in mid-cout without causing a catastrophic logical error.
__________________


Validate your Markup Validate your CSS Notepad++
Please use [html], [php], and [code] when posting code or markup.
I do not help by Private Message or e-mail. If for some reason I have over-looked a reply to a thread that I have previously replied to, then send me a message.
dm01 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 09-29-2008, 09:47 AM   #5 (permalink)
Design Team Member
 
jamiemac2005's Avatar
 
Join Date: Jul 2007
Location: Coventry, UK
Posts: 1,880
OS: Vista, various linux distros


Re: c++ help please -.-

Haha, sorry my last post was a lot of gibberish, it was late, forgive me.

This would be the basic algorithim behind converting a number into a string using %, / and a smaller switch case statement:

(example input = 189)
While the number is > 0:
- Modulus the number by 10 (would return 9)
- Use switch case between 0 and 9 to add "0"-"9" to the string
- Divide the number by 10 (would return 18)
- Modulus the number by 10 (would return 8)
- Use switch case again
- Divide the number by 10(would return 1)
- Modulus the number by 10 (would return 1)
- Use switch case again
- Divide the number by 10(would return 0 exiting the while loop)

Sorry, it's hard to know whether this is clear or not, but i can't explain this using C++ right now because for the life of me i can't remember enough C++ to do it... I expect it would be something like(though i haven't tested this):

Code:
//...other code here...
int numberToWorkOn = number_par;//the number to work on(as a parameter)
String myString = "";//an empty string
//while the number is bigger than 0
while(numberToWorkOn>0){
  //modulus the number by 10
  int tempNo = numberToWorkOn % 10;
  //work out what the digit is
  switch(tempNo){
    case 0:
      myString = "0"+myString;
    break;
    case 1:
      myString = "1"+myString;
    break;
//and so on until 9
  }

//divide the number by 10 and loop around
numberToWorkOn = numberToWorkOn/10;

}
The syntax there may be wrong(as i said i haven't used C++ in ages)... I hope this makes more sence now?

Cheers,
Jamey
__________________

Myspace
jamiemac2005 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 09-29-2008, 11:02 AM   #6 (permalink)
Registered User
 
darklordryu's Avatar
 
Join Date: Jul 2006
Location: Connecticut, US
Posts: 218
OS: Vista Desktop, XP Laptop

My System

Send a message via AIM to darklordryu
Re: c++ help please -.-

I actually had a friend somewhat explain that to me, something about using like say 99 was the first number...would do 99/10 as an int...would become 9, which would count as the 10's place number, and then 99 % 10 as an int to get 9, which would be the 1's place number...all this is so over my head, I'm sure you're explaining it perfectly clearly but when I see c++ my eyes just wanna close! lol

But I appreciate your help, at least now I have a visual model I can see and that really will help me out a ton, I really appreciate it, after I study it for a few hours I should get it lol
__________________
"Health and long life are the gifts of the spice!"
darklordryu is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 09-29-2008, 11:15 AM   #7 (permalink)
Design Team Member
 
jamiemac2005's Avatar
 
Join Date: Jul 2007
Location: Coventry, UK
Posts: 1,880
OS: Vista, various linux distros


Re: c++ help please -.-

lol haha, trust me i wasn't explaining it perfectly clearly... but if you understand what you're friend has said then you're okay =]

Hope all goes well.

Cheers,
Jamey
__________________

Myspace
jamiemac2005 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -7. The time now is 10:22 AM.



Copyright 2001 - 2009, Tech Support Forum
Home Tips Plus | Outdoor Basecamp | Automotive Support Forum

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85