C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 14th, 2005, 06:26 AM
jeci jeci is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 1 jeci User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 3 m 13 sec
Reputation Power: 0
splitting inputs....im so dumb =)

im so new at this so this is probably a really easy question for you all!!!

basically a user inputs a 7 digit number (eg..1234567)
and i need to split it into 2 parts

part1=1234
part2=567

how do i code this??? any help would be great!

Reply With Quote
  #2  
Old April 14th, 2005, 11:54 PM
B-Con's Avatar
B-Con B-Con is offline
:bcon: moderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Location: int main()
Posts: 351 B-Con User rank is Private First Class (20 - 50 Reputation Level)B-Con User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 23 h 1 m 43 sec
Reputation Power: 4
input the value as a string, then seperate the string.... ie:

Code:
char one[5],two[5];

gets(one);
strcpy(two,&one[5]);
one[5] = 0;


that's ugly, but the general idea you need.... also, if anyone else is gong to use the program, you will also need to add a check to ensure the length of the string input....
__________________
Officially a member of the Itsacon fan club. Beer blasts are every friday at Viper_SB's house. I bring the chips.



Reply With Quote
  #3  
Old April 18th, 2005, 06:28 PM
ubergeek ubergeek is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2005
Posts: 600 ubergeek User rank is Private First Class (20 - 50 Reputation Level)ubergeek User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 40 m 27 sec
Reputation Power: 4
Send a message via AIM to ubergeek
or do this:
Code:
#include <iostream>
using namespace std;

int main()
{
	int my8digitnumber;
	int first4digits, last4digits;
	cout << "Enter an eight-digit number: ";
	cin >> my8digitnumber;
	first4digits = my8digitnumber / 10000; //since first4digits is an integer variable, the decimal portion will be stripped off
	last4digits = my8digitnumber % 10000; // the % operator, called modulus, performs division returns the remainder
	cout << "First 4 digits: " << first4digits << ". Last 4 digits: " << last4digits << "." << endl;
	
	cin.ignore();
	cin.get();
	return 0;
}

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > splitting inputs....im so dumb =)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway