Speak now
Please Wait Image Converting Into Text...
Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Challenge yourself and boost your learning! Start the quiz now to earn credits.
Unlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
General Tech Learning Aids/Tools 2 years ago
Posted on 16 Aug 2022, this text provides information on Learning Aids/Tools related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
Turn Your Knowledge into Earnings.
I've created a variable length array in one function, however I need to refer to this array in a second function. The problem occurs when I put the declaration above main() seeing as its length hasn't been defined yet, my compiler gets angry.
How does one typically go about this?
EDIT:
Here is my code so far.
I need to make the array's name[] midterm[] and final[] global. They're all in student_input().
#include using namespace std ; void student_input(); void student_output(); int i , ns ; main(){ int width,height,mult; cout << "Enter the number of students:" << endl; cin >> ns; i = 0 ; while( i < ns){ i = i + 1 ; student_input(); } i = 0 ; while( i < ns){ i = i + 1 ; student_output(); } system("pause"); } void student_input() { int si_i,si_midterm,si_final, midterm[ns + 1], final[ns + 1]; string si_name, name[ns + 1]; cout << endl << endl << "\t----- Student " << i << " -----" << endl << endl << endl; cout << "Enter name for student " << i << ":\t"<< endl; cin >> si_name; name[i] = si_name ; cout << "Enter midterm score for student " << i << ":\t"<< endl; cin >> si_midterm; midterm[i] = si_midterm ; cout << "Enter final exam score for student " << i << ":\t"<< endl ; cin >> si_final; final[i] = si_final ; cout << endl << endl; si_i = 0 ; while (si_i < 7){ si_i = si_i + 1; cout << "Enter lab " << si_i <<" for student " << i << ":\t" REPLY 0 views 0 likes 0 shares Facebook Twitter Linked In WhatsApp
C++ does not support variable length arrays; either you are not using C++ or you are using an implementation-specific language extension.
In C++ you should use std::vector for a dynamically sized array.
std::vector
If you need to access it from multiple functions you can:
vector
Which one makes more sense depends on what, exactly, you are trying to do.
No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
General Tech 9 Answers
General Tech 7 Answers
General Tech 3 Answers
General Tech 2 Answers
Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.