Ask your own question, for FREE!
Computer Science 16 Online
OpenStudy (anonymous):

how do you use a constant variable in c++

OpenStudy (anonymous):

To make a constant variable, use the const keyword before declaration. For example: const int zero = 0; This value can be used, but cannot change throughout your program (it is read-only). For some purposes, you can instead use: #define zero 0

OpenStudy (anonymous):

@bdean20 well this what i have #include<iostream> using namespace std; const int NUMVALUES=10; int main() { double sum=0; double i, j; double number=0; double t1,t2,t3,t4; for(i=0;i<10;i++) { for(j=0;j<4;i++) { cout<<"enter the value of the test scores"<<endl; cin>>t1>>t2>>t3>>t4; t1=t1*.10; t2=t2*.25; t3=t3*.30; t4=t4*.35; sum=t1+t2+t3+t4; cout<<"the first student is "<<t1<<endl; cout<<"the seconde student is "<<t2<<endl; cout<<"the third student is "<<t3<<endl; cout<<"the fourth student is "<<t4<<endl; cout<<"the average scores are "<<sum/NUMVALUES <<endl; } } return 0; } i am just not to sure how i read write 10 sets of 4 grades based on user input

OpenStudy (anonymous):

You have 10 sets: for(i=0;i<10;i++) where i is the set. Then you have 4 grades: for(j=0;j<4;i++) where j is the set Then for each i and each j... So 40 times... You have 4 grades: cin>>t1>>t2>>t3>>t4; Either remove the second loop. OR Process one element each time you go through the inside loop. Also, if you need the sum of each group, you need to make sure you reset sum each time you enter the loop. What you're currently doing keeps track of the total of all grades so far for all students.

OpenStudy (anonymous):

@bdean20 would you know how to make an array for this

OpenStudy (anonymous):

I do, but if you haven't been taught how to use them yet, and you're doing it for a course, you're probably meant to do this without them.

OpenStudy (anonymous):

@bdean20 we have not been taught how in the course but i already know how to do them i just do not how to put the user input into a 10 by 4

OpenStudy (anonymous):

i can get it without the user input

OpenStudy (anonymous):

So, for example, you have: int grades[10][4]; If you want to insert values into this, you need to first index the correct student, but you also need to specify which assessment item it is: In your loop, identifying the element for a specific student and their grade would be: grades[i][j] You just need to set this whenever you write a grade and read from this to retrieve the grades. However, this problem doesn't require arrays and is probably far better without them. If this were to be scaled up, you wouldn't want to store all of the values locally.

OpenStudy (anonymous):

ok thanks for your help

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!