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 September 29th, 2004, 10:52 AM
galgalo galgalo is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 1 galgalo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
user to enter 10,1 to 4 digit values

Hi! my name is wako and I have a problem to figure out how to code this program,may someone direct me on how to go about it.
Any hint given is acceptable,
Thanks
This is how I code it,

#include<iostream>
using namespace stdd;

int main()
{
int num,int total = 0, int i,int goodcount = 0;
for ( i = 0; goodcount < 10; i++) {
cout << "Enter a 1 to 4 digit value:";
cin>> num ;
if (num<0)
cout << "value is negative and has been skipped:\n";
else if (num>0) continue;
goodcount++;
total = total + num;
}
cout << endl << "Sum of all values is :" << total << endl;
return 0;
}

note: This program is supposed only to accept 10 positive values if negative number or a value that exceeds 4 digit number is entered it display an error message.

Reply With Quote
  #2  
Old September 29th, 2004, 02:53 PM
The Phantom The Phantom is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Location: In the Dark City
Posts: 46 The Phantom User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
Send a message via AIM to The Phantom
with a quick 2 sec scan i see that you have else if. its "else"

and you dont need the continue thing its already there..

Reply With Quote
  #3  
Old September 30th, 2004, 03:02 PM
Kernel Mustard Kernel Mustard is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 32 Kernel Mustard User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
To find the number of digits in an integer do something like this.

int counter = 0;
int num = numberToCheck;

while ( num != 0) {
num = num/10;
counter++;
}

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > user to enter 10,1 to 4 digit values


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