For-loop

As you can see i want num0,num2,num4 to appear at the end with the name, but im having a hard time figuring out how to make the cin>>num0 change itself to num1,2,3, and 4 as it loops.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    char num0,num1,num2,num3,num4,name[50];   
    cout<<"Give me your name: ";
    cin>>name;
    
for (int i=1; i<=5; i++)
{
    
    cout<<("Press a number: ");
    cin>>num0;

}

cout<<name<<" " <<num0<<endl;
cout<<name<<" " <<num2<<endl;
cout<<name<<" " <<num4<<endl;
    
    
    system("PAUSE");
    return EXIT_SUCCESS;
}
You could create an array like char num[5]; instead, so that you can use its index to control which element you want to input.
BTW, on line 8, i guess you might need to declare name instead of an array.
Thanks you saved me.
Topic archived. No new replies allowed.