Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming

Reply
 
LinkBack Thread Tools
Old 07-24-08   #41 (permalink)
With great difficulty
 
rabidgnome229's Avatar
 
intel nvidia

Join Date: Feb 2006
Location: Pittsburgh
Posts: 5,210

Rep: 614 rabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famous
Unique Rep: 370
FAQs Submitted: 6
Trader Rating: 5
Default

What are the parameter bounds? Should it be able to handle amounts in the hundreds? Thousands? Billions?
__________________
System: It goes to eleven
CPU
E6300
Motherboard
DS3
Memory
2GB XMS2 DDR2-800
Graphics Card
EVGA 8600GTS
Hard Drive
1.294 TB
Sound Card
Audigy 2 ZS
Power Supply
Corsair 520HX
Case
Lian-Li v1000B Plus
CPU cooling
TTBT
GPU cooling
Thermalright V2
OS
Arch Linux/XP
Monitor
Samsung 226bw
rabidgnome229 is offline Overclocked Account   Reply With Quote
Old 07-24-08   #42 (permalink)
Photography nut
 
dangerousHobo's Avatar
 
amd nvidia

Join Date: Dec 2005
Location: ~/
Posts: 3,485

Rep: 409 dangerousHobo is a proven memberdangerousHobo is a proven memberdangerousHobo is a proven memberdangerousHobo is a proven memberdangerousHobo is a proven member
Unique Rep: 215
FAQs Submitted: 7
Trader Rating: 0
Default

I set it to be under a thousand, so your program should be able to handle any dollar amount smaller then that, but you can go higher.
__________________
"UNIX was never designed to keep people from doing stupid things, because that policy would also keep them from doing clever things." - Doug Gwyn

Try out the latest Programming Challenge
Quote:
Originally Posted by Melcar
Only one reasonable way to solve this... a dance off.

CPU-Z Validation
@ 2.97-prime95 stable 16 hours @ 1.48v Proof | CPU-Z Validation @ 3.15


Getting Mouse Side Buttons to work in Linux, Compile a custom Kernel, More

System: Anomaly
CPU
Athlon 3700 SD(KACAE)0546 @3.02ghz
Motherboard
DFI UT nF4 Ultra-D
Memory
G.Skill 2x512 UTT(BH-5)
Graphics Card
evga 6800gs
Hard Drive
Maxtor 300GB + WD 250GB
Sound Card
onboard
Power Supply
Ultra 500w V-series
Case
one from Ultra
CPU cooling
Big Typhoon
GPU cooling
80mm fan mounted on
OS
Arch64 & Slackware 12.1
Monitor
Acer AL2216W 22" WS LCD
dangerousHobo is offline Overclocked Account dangerousHobo's Gallery   Reply With Quote
Old 07-24-08   #43 (permalink)
With great difficulty
 
rabidgnome229's Avatar
 
intel nvidia

Join Date: Feb 2006
Location: Pittsburgh
Posts: 5,210

Rep: 614 rabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famous
Unique Rep: 370
FAQs Submitted: 6
Trader Rating: 5
Default

I just threw something together using a bash shell and ran into a problem. In bash $WHATEVER assumes WHATEVER is a variable (such as HOME or PATH) and expands it. Passing $12.11 expands $1 (to nothing) and passes only the string 2.11. In order to pass "$12.11" it must be in quotes or passed as \$12.11
__________________
System: It goes to eleven
CPU
E6300
Motherboard
DS3
Memory
2GB XMS2 DDR2-800
Graphics Card
EVGA 8600GTS
Hard Drive
1.294 TB
Sound Card
Audigy 2 ZS
Power Supply
Corsair 520HX
Case
Lian-Li v1000B Plus
CPU cooling
TTBT
GPU cooling
Thermalright V2
OS
Arch Linux/XP
Monitor
Samsung 226bw
rabidgnome229 is offline Overclocked Account   Reply With Quote
Old 07-24-08   #44 (permalink)
.
 
BiG O's Avatar
 
intel nvidia

Join Date: Jul 2007
Location: Virginia
Posts: 3,589

Trader Rating: 4
Default

So if we write this is something like java or c#, would it also be acceptable just to ask for the dollar amount? Maybe to allow someone to type as many as they want in a single line rather than having it stuctured like the run command you posted earlier. I'm going to assume yes while I start on this .
__________________
Imaging with Windows PE
Please keep the OCN Terms of Service in mind when posting.

System: My System
CPU
Q6700
Motherboard
Gigabyte p35-DS4
Memory
8GB Crucial Ballistix DDR2-800 (4x2GB)
Graphics Card
BFG 8800GTS 512MB g92
Hard Drive
2X 500GB Seagate Barracuda 7,200 RPM SATA RAID 0
Sound Card
Razer Barracuda AC-1 7.1
Power Supply
ABS 700W Modular
Case
Antec 900
CPU cooling
Apogee GTZ
GPU cooling
Stock
OS
Vista Ultimate x64 SP1, Xubuntu 8.10, Windows 7
Monitor
Hanns-G 28" & Dell 19" widescreen
BiG O is offline Overclocked Account   Reply With Quote
Old 07-24-08   #45 (permalink)
Photography nut
 
dangerousHobo's Avatar
 
amd nvidia

Join Date: Dec 2005
Location: ~/
Posts: 3,485

Rep: 409 dangerousHobo is a proven memberdangerousHobo is a proven memberdangerousHobo is a proven memberdangerousHobo is a proven memberdangerousHobo is a proven member
Unique Rep: 215
FAQs Submitted: 7
Trader Rating: 0
Default

Ok, it doesn't matter how someone can enter the amount to the program, just as long as it has a dollar sign($) and a decimal point.
__________________
"UNIX was never designed to keep people from doing stupid things, because that policy would also keep them from doing clever things." - Doug Gwyn

Try out the latest Programming Challenge
Quote:
Originally Posted by Melcar
Only one reasonable way to solve this... a dance off.

CPU-Z Validation
@ 2.97-prime95 stable 16 hours @ 1.48v Proof | CPU-Z Validation @ 3.15


Getting Mouse Side Buttons to work in Linux, Compile a custom Kernel, More

System: Anomaly
CPU
Athlon 3700 SD(KACAE)0546 @3.02ghz
Motherboard
DFI UT nF4 Ultra-D
Memory
G.Skill 2x512 UTT(BH-5)
Graphics Card
evga 6800gs
Hard Drive
Maxtor 300GB + WD 250GB
Sound Card
onboard
Power Supply
Ultra 500w V-series
Case
one from Ultra
CPU cooling
Big Typhoon
GPU cooling
80mm fan mounted on
OS
Arch64 & Slackware 12.1
Monitor
Acer AL2216W 22" WS LCD
dangerousHobo is offline Overclocked Account dangerousHobo's Gallery   Reply With Quote
Old 07-24-08   #46 (permalink)
.
 
BiG O's Avatar
 
intel nvidia

Join Date: Jul 2007
Location: Virginia
Posts: 3,589

Trader Rating: 4
Default

Quote:
Originally Posted by dangerousHobo View Post
Ok, it doesn't matter how someone can enter the amount to the program, just as long as it has a dollar sign($) and a decimal point.
sounds good. Should be fun.
__________________
Imaging with Windows PE
Please keep the OCN Terms of Service in mind when posting.

System: My System
CPU
Q6700
Motherboard
Gigabyte p35-DS4
Memory
8GB Crucial Ballistix DDR2-800 (4x2GB)
Graphics Card
BFG 8800GTS 512MB g92
Hard Drive
2X 500GB Seagate Barracuda 7,200 RPM SATA RAID 0
Sound Card
Razer Barracuda AC-1 7.1
Power Supply
ABS 700W Modular
Case
Antec 900
CPU cooling
Apogee GTZ
GPU cooling
Stock
OS
Vista Ultimate x64 SP1, Xubuntu 8.10, Windows 7
Monitor
Hanns-G 28" & Dell 19" widescreen
BiG O is offline Overclocked Account   Reply With Quote
Old 07-24-08   #47 (permalink)
With great difficulty
 
rabidgnome229's Avatar
 
intel nvidia

Join Date: Feb 2006
Location: Pittsburgh
Posts: 5,210

Rep: 614 rabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famous
Unique Rep: 370
FAQs Submitted: 6
Trader Rating: 5
Default

Here it is in C (not ideal for the task, but my default language) with the user input method. It does not check for erroneous input

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define BUFF_SIZE 1024

char *toString(int num);
char *makeString(char *buffer);

int main(int argc, char **argv){

	enum { file, arguments } mode;  //describes input type
	FILE *infile;	
	int i = -1;						//counts argument position
	char read_buffer[BUFF_SIZE], *string, *curr_pos, *decimal_ptr;
	int dollars, cents;	
	
	printf("Enter a string begining with $ to convert: ");
	while(fgets(read_buffer, BUFF_SIZE, stdin)){
		string = read_buffer;
		
		curr_pos = string;
		if(*curr_pos != '$'){
			printf("Done converting, exitingn");
			exit(1);
		}
		
		/* separate decimal from whole number amount */
		while(*curr_pos && (*curr_pos != '.')) curr_pos++;
		*curr_pos = '';
		decimal_ptr = ++curr_pos;
		curr_pos = string + 1;
		
		/* get integer values of dollars/cents */
		dollars = atoi(curr_pos);
		cents = atoi(decimal_ptr);
		char *d = (dollars == 1) ? "dollar" : "dollars";
		char *c = (cents == 1) ? "cent" : "cents";
		
		printf("%s %s and %s %sn", toString(dollars), d, toString(cents), c);
		printf("Enter a string begining with $ to convert: ");
	}
}

char *toString(int num){

	char *ones[] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
	char *teens[] = {"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
	char *tens[] = {"twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety" };
	char buffer[1024], *buff_ptr = buffer, *ret;
	buffer[0] = '';
	
	if(num == 0) return makeString(ones[0]);
			
	int index = num/100;
	if(index){
		strcpy(buff_ptr, ones[index]);
		buff_ptr += strlen(ones[index]);
		*buff_ptr++ = ' ';
		strcpy(buff_ptr, "hundred");
		buff_ptr += strlen("hundred");
		*buff_ptr = '';
	}
	num %= 100;
	
	index = num/10;
	if(index){
		if(buffer[0])
			*buff_ptr++ = ' ';
		
		if(index == 1){
			strcpy(buff_ptr, teens[num-10]);
			return makeString(buffer);
		}
		
		strcpy(buff_ptr, tens[index-2]);
		buff_ptr += strlen(tens[index-2]);
		*buff_ptr = '';
	}
	num %= 10;
	
	if(num){
		if(buffer[0])
			*buff_ptr++ = ' ';
		strcpy(buff_ptr, ones[num]);
	}
	
	return makeString(buffer);
}

char *makeString(char *buffer){
	char *ret;
	size_t len = strlen(buffer);
	if(len > 1024) return NULL;
	
	ret = malloc(sizeof(char) * len);
	strcpy(ret, buffer);
}
__________________
System: It goes to eleven
CPU
E6300
Motherboard
DS3
Memory
2GB XMS2 DDR2-800
Graphics Card
EVGA 8600GTS
Hard Drive
1.294 TB
Sound Card
Audigy 2 ZS
Power Supply
Corsair 520HX
Case
Lian-Li v1000B Plus
CPU cooling
TTBT
GPU cooling
Thermalright V2
OS
Arch Linux/XP
Monitor
Samsung 226bw

Last edited by rabidgnome229 : 07-24-08 at 09:53 PM
rabidgnome229 is offline Overclocked Account   Reply With Quote
Old 07-24-08   #48 (permalink)
.
 
BiG O's Avatar
 
intel nvidia

Join Date: Jul 2007
Location: Virginia
Posts: 3,589

Trader Rating: 4
Default

Good job man. I haven't even started yet haha.
__________________
Imaging with Windows PE
Please keep the OCN Terms of Service in mind when posting.

System: My System
CPU
Q6700
Motherboard
Gigabyte p35-DS4
Memory
8GB Crucial Ballistix DDR2-800 (4x2GB)
Graphics Card
BFG 8800GTS 512MB g92
Hard Drive
2X 500GB Seagate Barracuda 7,200 RPM SATA RAID 0
Sound Card
Razer Barracuda AC-1 7.1
Power Supply
ABS 700W Modular
Case
Antec 900
CPU cooling
Apogee GTZ
GPU cooling
Stock
OS
Vista Ultimate x64 SP1, Xubuntu 8.10, Windows 7
Monitor
Hanns-G 28" & Dell 19" widescreen
BiG O is offline Overclocked Account   Reply With Quote
Old 07-24-08   #49 (permalink)
Photography nut
 
dangerousHobo's Avatar
 
amd nvidia

Join Date: Dec 2005
Location: ~/
Posts: 3,485

Rep: 409 dangerousHobo is a proven memberdangerousHobo is a proven memberdangerousHobo is a proven memberdangerousHobo is a proven memberdangerousHobo is a proven member
Unique Rep: 215
FAQs Submitted: 7
Trader Rating: 0
Default

I did want solutions posted so early but I guess it doesn't really hurt.

Edit: looks a little messy if you don't know ruby, but works.

Code:
$ time ruby challenge_1.rb $56.08
"fifty six dollars and eight cents"

real	0m0.008s
user	0m0.004s
sys	0m0.003s
Code:
#!/usr/bin/ruby

d1 = ARGV.shift

ones = { 0 => "", 1 => "one", 2 => "two", 3 => "three", 4 => "four", 
         5 => "five", 6 => "six", 7 => "seven", 8 => "eight", 9 => "nine",
         10 => "ten", 11 => "eleven", 12 => "twelve", 13 => "thirteen", 14 => "fourteen",
         15 => "fifteen", 16 => "sixteen", 17 => "seventeen", 18 => "eighteen", 19 => "nineteen" }

tens = { 0 => "", 1 => "ten", 2 => "twenty", 3 => "thirty", 4 => "fourty", 
         5 => "fifty", 6 => "sixty", 7 => "seventy", 8 => "eighty", 9 => "ninety" }

d1 = d1.split('').map {|x| x.to_i}
d1.shift
d1[-3] = '.'
f = String.new
f = "#{ones[d1.shift]} hundred and " if d1.join.to_f > 100
if d1.join.to_f > 20.00
  f.concat "#{tens[d1.shift]} #{ones[d1.shift]} dollars "
else
  f.concat "#{ones[d1.shift]} #{ones[d1.shift]} dollars "
end
d1.shift
if d1.join.to_i < 20
  f.concat "and #{ones[d1.join.to_i]} cents"
else
  f.concat "and #{tens[d1.shift]} #{ones[d1.shift]} cents"
end

p f
__________________
"UNIX was never designed to keep people from doing stupid things, because that policy would also keep them from doing clever things." - Doug Gwyn

Try out the latest Programming Challenge
Quote:
Originally Posted by Melcar
Only one reasonable way to solve this... a dance off.

CPU-Z Validation
@ 2.97-prime95 stable 16 hours @ 1.48v Proof | CPU-Z Validation @ 3.15


Getting Mouse Side Buttons to work in Linux, Compile a custom Kernel, More

System: Anomaly
CPU
Athlon 3700 SD(KACAE)0546 @3.02ghz
Motherboard
DFI UT nF4 Ultra-D
Memory
G.Skill 2x512 UTT(BH-5)
Graphics Card
evga 6800gs
Hard Drive
Maxtor 300GB + WD 250GB
Sound Card
onboard
Power Supply
Ultra 500w V-series
Case
one from Ultra
CPU cooling
Big Typhoon
GPU cooling
80mm fan mounted on
OS
Arch64 & Slackware 12.1
Monitor
Acer AL2216W 22" WS LCD

Last edited by dangerousHobo : 07-24-08 at 10:43 PM
dangerousHobo is offline Overclocked Account dangerousHobo's Gallery   Reply With Quote
Old 07-24-08   #50 (permalink)
Programmer
 
alawadhi3000's Avatar
 
intel nvidia

Join Date: Oct 2005
Location: Bahrain
Posts: 1,766

Rep: 147 alawadhi3000 is acknowledged by manyalawadhi3000 is acknowledged by many
Unique Rep: 106
Folding Team Rank: 312
Hardware Reviews: 5
Trader Rating: 28
Default

Here's my code in C++

Code:
#include<iostream>
using namespace std;

//Printing Function
void print(int a)
{

int temp;
temp=a;
int i=0;
int tens=0;
int temp2;


temp2=temp;
i=temp2/100;
if(i==1) cout<<"One";
else if(i==2) cout<<"Two";
else if(i==3) cout<<"Three";
else if(i==4) cout<<"Four";
else if(i==5) cout<<"Five";
else if(i==6) cout<<"Six";
else if(i==7) cout<<"Seven";
else if(i==8) cout<<"Eight";
else if(i==9) cout<<"Nine";
if(i>0 && i<10)
cout<<" Hundred ";


temp2=temp;
i=temp2%100;
i=i/10;
if(i>0)
{
	if(i==2) cout<<"Twenty";
	else if(i==3) cout<<"Thirty";
	else if(i==4) cout<<"Fourty";
	else if(i==5) cout<<"Fifty";
	else if(i==6) cout<<"Sixty";
	else if(i==7) cout<<"Seventy";
	else if(i==8) cout<<"Eightty";
	else if(i==9) cout<<"Ninety";
	tens=i;
	cout<<" ";
}

temp2=temp;
i=temp2%10;

if(tens==1)
{
if(i==1) cout<<"Eleven";
	else if(i==2) cout<<"Twelve";
	else if(i==3) cout<<"Thirteen";
	else if(i==4) cout<<"Fourteen";
	else if(i==5) cout<<"Fifteen";
	else if(i==6) cout<<"Sixteen";
	else if(i==7) cout<<"Seventeen";
	else if(i==8) cout<<"Eighteen";
	else if(i==9) cout<<"Nineteen";
}

else if(i>0)
{
	if(i==1) cout<<"One";
	else if(i==2) cout<<"Two";
	else if(i==3) cout<<"Three";
	else if(i==4) cout<<"Four";
	else if(i==5) cout<<"Five";
	else if(i==6) cout<<"Six";
	else if(i==7) cout<<"Seven";
	else if(i==8) cout<<"Eight";
	else if(i==9) cout<<"Nine";
}

cout<<endl;
}
//end of Function


//Main
int main()
{
int amount=0;
char dollar;

cout<<"Menu"<<endl;


	cout<<"Please Enter the amount with the dollar sign first"<<endl;
	cin>>dollar>>amount;

	while(amount<0 || amount>1000)
	{
	cout<<"Please Enter the amount with the dollar sign first"<<endl;
	cin>>dollar>>amount;
	}


print(amount);



int b;
cout<<"Enter anything to Exit"<<endl;
cin>>b;
return 0;
}
After I finished I realized that the program should accepts two numbers after decimal point

Also it only accepts entering the data manually as I wanted to code it fast

I will try to fix them later
__________________
GeForce 8800GTS 320MB/9600GT/8800GT

3DMark06 11518/10963/13622
3DMark05 17948/17446/23147
3DMark03 36902/36240/42768
3DMark01 49944/43675/53827

Total 116312/109324/133364

System: My Rig
CPU
Q9550 @ 3.4GHz + E8400 @ 3.6GHz 1.15v 24/7
Motherboard
Intel DX48BT2
Memory
4GB OCZ Intel Extreme DDR3-1600 (2X2GB)
Graphics Card
XFX 8800GT Alpha Dog Zalman Edition
Hard Drive
500GB Seagate 7200.12 + 1TB WD Green + 320GB WD
Sound Card
SigmaTel STAC9274D
Power Supply
Antec True Power 750W
Case
Thermaltake Soprano
CPU cooling
Thermaltake Big Typhoon + CM 90CFM Fan
GPU cooling
Zalman Stock Heatsink
OS
Windows 7 X64
Monitor
ASUS VH242HL-P
alawadhi3000 is offline I fold for Overclock.net   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -5. The time now is 03:15 PM.


Overclock.net is a Carbon Neutral Site Creative Commons License

Terms of Service / Forum Rules | Privacy Policy | DMCA Info | Advertising | Become an Official Vendor
Copyright © 2009 Shogun Interactive Development. Most rights reserved.
Page generated in 0.18965 seconds with 9 queries