#"Identifier is undefined"
1 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
{
int TotalGrade = 1000;
int grade;
char Assignment(string assignment); {
cout << "Please enter the score for " << assignment;
cin >> grade;
}
Assignment("Assignment #01");
_getch();
return 0;
}```
It's saying "assignment" is undefined
You can't define a function inside another function
It depends on the language
C and C++ you can't (save for lambdas in c++)
I get so confused with C and C++
if I take it out of main it just fills with tons of errors
What is the error in question?
Can you share your updated code?
int TotalGrade = 1000;
int grade;
char Assignment(string assignment); {
cout << "Please enter the score for " << assignment;
cin >> grade;
}
Assignment("Assignment #01");
_getch();
return 0;
You still need a main function.
Code does not execute outside of a function
I'm so confused, you said I can't define a function inside of it
Put main around the code AFTER the Assignment function
int TotalGrade = 1000;
int grade;
char Assignment(string assignment);
{
cout << "Please enter the score for " << assignment;
cin >> grade;
}
main() {
Assignment("Assignment #01");
_getch();
return 0;
}
now I'm getting "Type char unexpected"
Okay last thing, you don't need a ; between the function arguments and the body of Assignment's definition
Oh and you need main to return an int
Add the word int in front of main
- The Assignment function name is not good as it doesn't describe what the function does. Maybe input_grades could be used as it's name?
- Since grade is a integer value you should return int.
- The value returned from the function call is not being assigned to a variable.
- Not sure what the _getch() is for
tbh our teacher puts _getch() in every single template but never told us what it's for
It doesn't run properly without it, gives me a bunch of weird stuff at the end of the console without it
The function is purely so I don't have to repeat 13 lines of code
I get that but function names have to be descriptive
without looking at the implementation you should figure out what it does just by the name
I mean it quite literally just replaces the assignment name
I have another question tho @knotty vale, How can I use the cin value to add to a variable instead of setting it
cout << "Please enter the score for " << assignment << ": ";
cin >> grade;
return 0;
I want cin to add to 'grade' instead of setting it
You would need an array or vector if I'm understanding what you're saying correctly
Would you mind giving me an example?
You mean like tracking multiple student grades right?
So the assignment is a grade calculator, I take the grades of multiple assignments and essentially output a prediction of how much I need to get certain grades
I'm wanting to make it so when you input the grade of an assignment, it adds that input to the "grade" variable
instead of setting it
If you know the specific amount of grades to input using an array is pretty good otherwise you can use a vector.
This is the example for an array
int grades[10];
for(int i = 0; i < grades.size(); i++){
std::cin >> grades[i];
}
@woeful pilot Has your question been resolved? If so, type !solved :)
I'm not sure how I would implement that in my program
I must've accidentaly skipped something in my course lmao
I’m guessing for every assignment it lists the amount of students, so I’ll keep going with arrays
Learncpp.com has information about this
It's not for multiple students
it's a personal grade calculator, only needs the one grade total
Can you post the assignment details cause if it’s a personal grade calculator you could do it all in the main function
I figured it out lmao, incredibly simple
LIterally just created a second variable, and inside of the function added the "grade" variable to the "totalgrade"
it's an extra line of code than what I had intended but it works perfect
Yea, I saw in the #cpp-help-text
{
cout << "Please enter the score for " << assignment << ": ";
cin >> grade;
TotalGrade = grade + TotalGrade;
return 0;
}```
Make the char Assignment_Grade return void if you don’t have to return anything