Click here to Skip to main content
15,906,645 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I'm trying to create a program that can accept infinite inputs and add them up. The input will be put in a text-box and submitted with a button. Any suggestions?
Posted
Comments
[no name] 14-Oct-12 13:02pm    
Get input, add to total, get input, add to total, repeat infinitely.
Curtdawg123 14-Oct-12 13:21pm    
thanks

1 solution

C#
//u need to add  System.Text.RegularExpressions;
//Input is ur input string
string[] Numbers = Regex.Split(Input, @"\D+");
int Temp=0,Sum=0;
foreach(string i in Numbers)
if(int.TryParse(i,out Temp))
Sum += Temp;

Above code will take only Numbers.
Skips all Non-Digit characters, so to separate any number use any Non-Digit character
 
Share this answer
 
Comments
Maciej Los 14-Oct-12 15:36pm    
Good job, +5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900