This solution won't work for you, but it should give you a push in the right direction:
#include <iostream>
using namespace std;
char letter_grade(int grade_num)
{
char limit[][4] = {90,80,70,60,'A','B','C','D'};
for (int i = 0; i < 4; i++) {
if (grade_num >= limit[0][i])
return limit[1][i];
}
return 'F';
}
bool is_passing(char grade_letter)
{
return grade_letter < 'F'; // Portability is for wusses
}
int main()
{
for (int i = 0; i < 101; i++) {
cout<< i <<" = "<< letter_grade(i) <<": ";
cout<< boolalpha << is_passing(letter_grade(i)) <<endl;
}
}
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
You realize you're paying to be taught, right? Don't just sit there and whine about the instructors not doing their part, make them do it.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>i don't know if that will work
So run it and see. If you aren't confident that your code is 100% correct, don't write directly to the thread. Write the code in an editor, compile it, run it, debug it, and make sure it's working like you expect before posting it.
To this day, I still test my code before posting it 9 times out of 10. I'm confident that it's flawless (though part of that is ego), but I still would rather double and triple check myself than have somebody else correct a stupid mistake.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>use public computers i don't have one of my own
Blah blah blah, stop making excuses and start finding solutions. Here's one.
>*wonders if it would work*
No, it wouldn't.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>If so, what about it won't work.
iostream? namespace?
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>i left that out thinking it was a "given"
You'd be surprised at how many people won't see it that way. If you post code that could be mistaken for a complete program, make sure it compiles and runs as is.
>i didn't have to add "using namespace std;" like you did though, wonder why!?!?!?
Because you qualified each standard name with std::. There are three ways to qualify names in a namespace. Opening up the entire namespace like I did is one way and handling names on a case by case basis like you did is another. The third way is with a using declaration:
#include <iostream>
// Only allow cout and endl as unqualified names
using std::cout;
using std::endl;
int main()
{
cout<<"Hello, world!"<<endl;
}
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401