how to complete my code arrays :D

closed account (Nvq4jE8b)
#include <iostream.h>

int main()
{

int grade[20];

for(int i=0;i<20;i++)
{
cout<<"Enter grade: "<<(i+1)<<" ";
cin>>grade[i];
}

for (int j=0;j<20;j=j+5)
{

cout<<"\nYour grade now is: "<<grade[j];

}

return 0;

}

The question was to enter 20 grade then add 5 points to each grade then display the result of each new grade.... I cannot complete the code
Last edited on
I'm no expert, but don't you need a "using namespace std;"?
1
2
3
4
5
6
for(int i=0;i<20;i++)
{
cout<<"Enter grade: "<<(i+1)<<" ";
cin>>grade[i];
grade[i] += 5; // add 5 points to each grade entered
}
closed account (Nvq4jE8b)
hmmm im using c++ 4.5 so using namespace std; still doesnt work
closed account (Nvq4jE8b)
return 0 thanks for the code but its still doesnt work
What are you trying to do and what isn't working?
It seems like your asking for an array (line 11) and printing an array (line 17)...
According to my knowledge it isn't possible to print or ask an array in that way...
But ofcourse I might be totally wrong, suggestion: try it using 'int' or 'struct'
return 0 thanks for the code but its still doesnt work

What's wrong with the code snippet?

Note that this code
1
2
3
4
5
6
for (int j=0;j<20;j=j+5)
{

cout<<"\nYour grade now is: "<<grade[j];

}


Will only output every 5th grade. If your trying to output all of them you need to change it to:
for (int j = 0; j < 20; j++ )

It seems like your asking for an array (line 11) and printing an array (line 17)...
According to my knowledge it isn't possible to print or ask an array in that way...
But ofcourse I might be totally wrong, suggestion: try it using 'int' or 'struct'


What? There's nothing wrong with the way the OP is reading in or outputting the numbers.
LOL, I'm totally newb :$ x]
Is it because the only variable you declare is the grade[] array? It looks like akosinoah copy pasted his entire program so the int 'j' and\or 'i' are never declared within ANY part of the program.

Try changing this at the top

int main()
{

int grade[20],i,j;
Last edited on
@Computergeek01

i and j was declared inside for statements!!

Return 0 codes was correct..
closed account (Nvq4jE8b)
thank you very much guys.... u helped me alot.
closed account (Nvq4jE8b)
thank you very much guys.... u helped me alot.
Bah, it's still bad form for that reason! Just because you CAN do something in C doesn't mean you should.
that would be done if you want some variables to locally defined in a certain blocks..
Topic archived. No new replies allowed.