| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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.. |
|
#3
|
|||
|
|||
|
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++; } |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > user to enter 10,1 to 4 digit values |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|