for loop problem

hello there i have here a problem pls help me analyze here it says
create a program that accepts 5 integers. calculate and display
the sum of 5 input integers.

and the other is make a program that accepts 5 characters and
display the number of digits among the 5 input characters... just teach
me how to analyze the problem using for loop statement. thanks in advance....
1.) Omfg...really?

2.) I don't understand the question...could you rephrase it please?

This is the basic code for a for loop statement.

1
2
3
4
5
for(int i = 0; i < 5; i++) {

//add your code into here, it will run 5 times. 

}


This forum have a really good tutorial section: check it out: http://www.cplusplus.com/doc/tutorial/control.html
sir firedraco i have a problem in for loop statement here is the
no. 1.) create a program that accepts 5 integers. calculate and display
the sum of 5 input integers.

no.2.) make a program that accepts 5 characters and
display the number of digits among the 5 input characters.

these problem is very difficult for me to analyze being a begginner in c++.
just help me analyze what to do... tia
display the number of digits among the 5 input characters
That makes no sense.
When someone asks you to rephrase it means that you should make what you said, clearer, not just repeat it. If he wanted to, he could just your original post.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//no.1
int sum,num;
sum=0;
for(int i=0;i<5;i++)
{
cin>>num;
sum+=num;
}
cout<<sum;

//no.2
#include<iostream>
using namespace std;
int main()
{
    char str[6]; //no of characters in a c style array =subscript-1
    cin>>str;
    for(int i=0;i<5;i++)
    {
        if(str[i]>='0' && str[i]<='9') //check if str[i] is a digit or not
        cout<<str[i]<<" is a digit."<<endl;
    }
    return 0;
}

The second one's just slightly more complicated than you would expect. For a newbie that is.
Poke386, try not to just post the code that answers his problems, it doesn't actually teach him anything. As soon as he has a different problem he won't know what to do. At the very least he should post his own code before you offer sample code/corrections.
@poke386 thanks sir for your help being a begginner it takes me more time to understand these for loop statement i spend 3 hrs trying to solve the problem i try to visit these forum again and here is it., thanks a lot sir. @ jpeg thanks sir your concern for me to learn bout these problem it is that we have only given one for loop example by our prof and as a begginner it is very hard for me to understand... don't worry i'll try to catch up with it... anyway to those who reply it is highly appreciated.
Topic archived. No new replies allowed.