@dhayden, hey mate, how are you?
that's another example, we pass the while and do while loop so now the purpose is a little different.
that's the full code
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 45
|
int n,s=0;
cout<<" Enter n=";
cin>>n;
for(int i=0,a,b,c,rez,j,k=0; i < n ; i++)
{
do{
a=rand()%20;
}while(a%2!=0);
do {b= rand()%100;
k++;
}while ( b < 50 && b > 70 );
cout<<"b got incorrect values for "<<k<<endl;
c=rand()%20;
rez=a+b-c;
s+=rez;
//
for(int u = 0; u<n && s>10 && s<50; u++) //you can move the if condition into the loop.
cout << "S for "<<s<<" times"<<endl;
//
cout<<setw(4)<<i+1<<" a="<<a<<" b="<<b<<" c="<<c<<" a+b-c="<<rez<<endl;
j=0;
while(rez%2==0 && j<3)
{
a=rand()%100+100;
b=rand()%100+100;
c=rand()%100+100;
cout<<"\t "<<setw(4)<<j+1<<" a="<<a<<" b="<<b<<" c="<<c<<" a+b-c="<<a+b-c<<endl;
j++;
}
}
cout<<" s="<<setw(3)<<s<<endl;
return 0;
}
|
i have to edit it to the final version, but that's what i've done so far.
the conditions are below :
1. solve a+b-c for "n" number of times.
2. If the result is even, add 3 more iterations of a+b-c, where a,b,c have values from 0-100.
3. variable a should receive only even values.
4. If the Sum of the results is bigger then 10 and smaller then 50, the last solved result should be printed out for "n" number of times. Note that "n" number of times is set up by the user(operator cin).
5. variable b should receive random values from 0-100, where just values from 50-70 will be considered as correct values. We should count how many times variable b received incorrect values( incorrect are the ones beside the interval 50-70, as initially variable b had the interval 0-100)