Hello, I am a student taking C++ , and I am asking for help for my homework, not that I am asking to help me do my homework, but I have a problem with the code (Which I wrote)
But before anyone calls me lazy, I would like to apologize , as I have no one to turn to for help (I am in my term break) .
This is the code in question :
#include <ctime>
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
srand(time(0));
int studentScore = rand() % 100 + 1;
int studentAssignment = rand() % 100 + 1;
int studentAttendance = rand() % 100 + 1;
The problem with my code is that It will not display the grades "A" "C" "F" and "grade cannot be determined" , I can build and run this solution without problem, but I am unable to get the fourth output , So I would like an expert to tell me my problem, I would really want to learn this , so I would like to request hints, and not the entire solution .....well at least until I am clueless...Thank you,
First off, I'd like to ask you to use code tags. You can get them with the little button to the right of the window that looks like <>. I've reformatted your code for you, and also condensed your if-elses.
The next thing to note is that I'm still waking up, so I might be missing something obvious.
The final thing to note is that all your grade-giving if-elses will only work if the student attendance is above 85. Otherwise, nothing will be printed. Assuming that the values from your random number generation are evenly-distributed, that whole code has a roughly 0.15 probability of running.
might not always be greater than 85 as it is randomly generated, when the application generates a value of less than 85 everything inside of: if(studentAttendance >85) will not execute.
For debugging purposes, you might want to add: studentAttendance = 90; to override your randomly generated value for this, so you can see the rest of the code execute.
Although not essential you may want to add some boolean (bool) variables to mask the contents of the if statements to make it more understandable. For example:
bool fAttendanceOK = studentAttendance >85; and have if( fAttendanceOK ). bool fIsA = studentAssignment>79 && studentScore>79; and have if( fIsA ).
You also need to put return 0; at the end of your main function (as in the prototype it says you will return an int).
IamSebastian first of all your if (studentAssignment = 0 && studentScore <41 ) condition doesn't do what you want.......change studentAssignment = 0 to studentAssignment == 0 because you compare studentAssignment with 0......
and then it could be problem connecting with prioritets......i'm not sure for 100% but