Problem with += ...
Hello. I'm new here.
I have this 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
|
#include <iostream>
using namespace std;
int main(){
int a;
int i;
float pr;
int br=0;
for ( i=1; i<=5;i++){
cout<<"Unesite ocjenu: "<<i<<endl;
cin>>a;
if (a>=1 && a<=5) {
pr+=a;
br=i;
}
else
cout <<"ocjena nije dobra";
}
pr/=br;
cout <<"prosjek je:"<<pr<<endl;
return 0;
}
|
Well this:
pr+=a;
br=i;
"pr" should be sum of five "a". And then I need to pr /= br ...
Thanks!
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
|
#include <iostream>
using namespace std;
int main(){
int a=0; //<-----changed
int i;
float pr;
int br=0;
for ( i=1; i<=5;i++)
{
cout<<"Unesite ocjenu: "<<i<<endl;
cin>>a;
if (a>=1 && a<=5) {
pr+=a;
br=i;
}
else
cout <<"ocjena nije dobra";
}
pr/=br;
cout <<"prosjek je:"<<pr<<endl;
return 0;
}
|
Precent is again in minus.
prosjek = precent ...
Sorry, I was not paying that much attention.
1 2 3 4 5
|
//Initialise all your variables before using them!
int a = 0;
int i = 0;
float pr = 0.0;
int br = 0;
|
Last edited on
Thanks man ! :)
Topic archived. No new replies allowed.