problme if i change constate with a variable !!

Write your question here.
new i have another question
if i change number 3 [ for(int x=0; x< 3); x++) ] with a variable , the programe won't work.

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
  




#include <iostream>
#include <string>

using namespace std;

struct Wgwagner
{
string fullname;
unsigned int ZimNum;
string Stdgg;
};

int main()
{

int n; // if i use this 2.lines ,the programe won't work 
cin>> n; //
Wgwagner personel[100];

for (int x = 0; x < n; x++) //    i replaced  a constane with a variable n
{
cout << "Enter name #" << x + 1 << " : ";
getline(cin, personel[x].fullname);

cout << "Enter ZimNum " << x + 1 << " : ";
cin >> personel[x].ZimNum;
cin.ignore(10, '\n');
cout << "Enter Stdgg #" << x + 1 << " : ";
getline(cin, personel[x].Stdgg);
cout << endl;
}
cout << endl << endl;
for (int x = 0; x < n; x++) //  //    i replaced  a constane with a variable n
{
cout << personel[x].fullname << " " << personel[x].ZimNum << " " << personel[x].Stdgg << endl;
}
return 0;
}
Last edited on
What is your Question ?
question : when the programe runs , it's writes "Enter ZimNum " and "Enter Stdgg #" at the sametime . it must wait until i typ a number or something else
closed account (2LzbRXSz)
Put cin.ignore(); under/after cin >> n; This will fix the problem:)
Last edited on
thank you very much catctus :-)
closed account (2LzbRXSz)
No prob bob
Topic archived. No new replies allowed.