I dont wanna argue.... anywho yeah i think it needs to be an integer and i need to use modulus to get the 2nd digit
Printable View
Then format your code according to a reasonable style. Put it another way: if you consistently write code that is hard to read and understand, people will eventually give up reading. In this community, that means that you won't get any help.Quote:
Originally Posted by ferfy
Yes. Well, if you read it as a string first then you don't need to do it that way, but it would probably be easier to understand.Quote:
Originally Posted by ferfy
Dont wanna argue about style....anywho this is the updated code:
Code:
#include <iostream>
#include <string>
int main()
{
int grade;
std::cout << "Enter your grade %: ";
std::cin >> grade;
if (grade <= 60) {
std::cout << "You scored an F\n"; }
if (grade > 61 && grade <= 70) {
std::cout << "You scored a D\n"; }
if (grade % 10 <= 3) {
std::cout << '-'; }
if (grade % 10 > 7 || grade % 10 == 0) {
std::cout << '+'; }
if (grade > 71 && grade <= 80) {
std::cout << "You scored a C\n"; }
if (grade % 10 <= 3) {
std::cout << '-'; }
if (grade % 10 > 7 || grade % 10 == 0) {
std::cout << '+'; }
if (grade > 81 && grade <= 90) {
std::cout << "You scored a B\n"; }
if (grade % 10 <= 3) {
std::cout << '-'; }
if (grade % 10 > 7 || grade % 10 == 0) {
std::cout << '+'; }
if (grade > 91 && grade <= 100) {
std::cout << "You scored an A!\n"; }
if (grade % 10 <= 3) {
std::cout << '-'; }
if (grade % 10 > 7 || grade % 10 == 0) {
std::cout << '+'; }
}
It compiles fine, but for some reason the output is wrong.... -_-
not sure why, anyone mind helping me out?
i dont wanna argue about coding style... here's the updated code, it compiles fine, but for some reason the outputs wrong.... WHY DO MY POSTS KEEP NOT SHOWING UP/DELETED? WTF
Code:#include <iostream>
#include <string>
int main()
{
int grade;
std::cout << "Enter your grade %: ";
std::cin >> grade;
if (grade <= 60) {
std::cout << "You scored an F\n"; }
if (grade > 61 && grade <= 70) {
std::cout << "You scored a D\n"; }
if (grade % 10 <= 3) {
std::cout << '-'; }
if (grade % 10 > 7 || grade % 10 == 0) {
std::cout << '+'; }
if (grade > 71 && grade <= 80) {
std::cout << "You scored a C\n"; }
if (grade % 10 <= 3) {
std::cout << '-'; }
if (grade % 10 > 7 || grade % 10 == 0) {
std::cout << '+'; }
if (grade > 81 && grade <= 90) {
std::cout << "You scored a B\n"; }
if (grade % 10 <= 3) {
std::cout << '-'; }
if (grade % 10 > 7 || grade % 10 == 0) {
std::cout << '+'; }
if (grade > 91 && grade <= 100) {
std::cout << "You scored an A!\n"; }
if (grade % 10 <= 3) {
std::cout << '-'; }
if (grade % 10 > 7 || grade % 10 == 0) {
std::cout << '+'; }
}
You should tell us the test input, the expected output and the actual output.Quote:
Originally Posted by ferfy
Why are you ignoring my suggestion to indent the code properly?Quote:
Originally Posted by ferfy
Look, yes, this is an issue of subjective style. But your style sucks, plain and simple. If you don't fix it, I will mind helping you out. No, not because I want you to follow my own style (which I have not used in this thread), but because I want to be able to read and understand your code without having to constantly get it re-formatted to be readable.
test input: 71, expected output: C-
Actual output: -----
Another example: test input: 50 expected output: F+
actual output: You scored an F
-+-+-+-+
I dont like your style of indenting.... but since u can't read mine from now on i'll try to use your style......and i dont see why u can't read mine, it's very easy.....
EDIT: Besides.... So far i haven't received much help... i've received more help from my friends on irc/skype and none of them complained that my code wasn't readable.... they didn't complain at all about my style for that matter.
Why do you indent your code?Quote:
Originally Posted by ferfy
To answer my own question: I indent code so that the reader can easily see where blocks of scope are marked out. Thus, I indent the body of a function by one level so it is easily to see what is the body of the function. I indent the body of the block of an if statement or loop by one level for the same reason.
What's your reasoning, and how does your style match it?
You cannot read your own code either. If you could, you would have easily discovered the reason for the incorrect output that you are getting now. In fact, as soon as I indented your code properly, your mistake became so blatantly obvious that I pointed it out to you in post #15.Quote:
Originally Posted by ferfy
I am not insisting that you indent properly because I am trying to impose my style on you. I am insisting that you indent properly because it helps you to write correct code.
This is not a style issue. Your code is improperly indented. Indentation indicates the block structure of the code and shows what statements a conditional or loop statement controls.
This:
Is wrong.Code:if (grade > 61 && grade <= 70) {
std::cout << "You scored a D\n"; }
if (grade % 10 <= 3) {
std::cout << '-'; }
if (grade % 10 > 7 || grade % 10 == 0) {
std::cout << '+'; }
It should be like this (keeping your brace style)
If you feel it should be indented differently, then you are probably misreading what your braces are saying. Maybe you mean thisCode:if (grade > 61 && grade <= 70) {
std::cout << "You scored a D\n"; }
if (grade % 10 <= 3) {
std::cout << '-'; }
if (grade % 10 > 7 || grade % 10 == 0) {
std::cout << '+'; }
Notice (with some difficulty) that I've moved the brace from the second line down to the end of the last line. Normal brace placement would make this more obvious:Code:if (grade > 61 && grade <= 70) {
std::cout << "You scored a D\n";
if (grade % 10 <= 3) {
std::cout << '-'; }
if (grade % 10 > 7 || grade % 10 == 0) {
std::cout << '+'; } }
OrCode:if (grade > 61 && grade <= 70) {
std::cout << "You scored a D\n";
if (grade % 10 <= 3) {
std::cout << '-';
}
if (grade % 10 > 7 || grade % 10 == 0) {
std::cout << '+';
}
}
Code:if (grade > 61 && grade <= 70) {
std::cout << "You scored a D\n";
if (grade % 10 <= 3)
std::cout << '-';
if (grade % 10 > 7 || grade % 10 == 0)
std::cout << '+';
}
i indent 1 level per if or loop...... same as you.. idk what you mean... b/c that's exactly what i'm doing..... ?!?!?!?
modified the code a bit, works better, but still wrong output.... 1-3 works fine (except it gives additional '-'s), 4-7 works fine, 8-9 & 0 do not work...... (These are for the 2nd digits for the - or +)
Code:#include <iostream>
#include <string>
int main()
{
int grade;
std::cout << "Enter your grade %: ";
std::cin >> grade;
if (grade <= 60) {
std::cout << "You scored an F\n"; }
if (grade > 61 && grade <= 70) {
std::cout << "You scored a D\n"; }
if (grade % 10 <= 3) {
std::cout << '-'; }
if (grade % 10 > 7 || grade % 10 == 0) {
std::cout << '+'; }
if (grade > 70 && grade <= 80) {
std::cout << "You scored a C\n"; }
if (grade % 10 <= 3) {
std::cout << '-'; }
if (grade % 10 > 7 || grade % 10 == 0) {
std::cout << '+'; }
if (grade > 80 && grade <= 90) {
std::cout << "You scored a B\n"; }
if (grade % 10 <= 3) {
std::cout << '-'; }
if (grade % 10 > 7 || grade % 10 == 0) {
std::cout << '+'; }
if (grade > 90 && grade <= 100) {
std::cout << "You scored an A!\n"; }
if (grade % 10 <= 3) {
std::cout << '-'; }
if (grade % 10 > 7 || grade % 10 == 0) {
std::cout << '+'; }
}
Wow. :(
thanks oogabooga.... final code:
Code:#include <iostream>
#include <string>
int main()
{
int grade;
std::cout << "Enter your grade %: ";
std::cin >> grade;
if (grade <= 60) {
std::cout << "You scored an F\n"; }
if (grade > 61 && grade <= 70) {
std::cout << "You scored a D\n";
if (grade % 10 <= 3)
std::cout << '-';
if (grade % 10 > 7 || grade % 10 == 0)
std::cout << '+'; }
if (grade > 70 && grade <= 80) {
std::cout << "You scored a C\n";
if (grade % 10 <= 3)
std::cout << '-';
if (grade % 10 > 7 || grade % 10 == 0)
std::cout << '+'; }
if (grade > 80 && grade <= 90) {
std::cout << "You scored a B\n";
if (grade % 10 <= 3)
std::cout << '-';
if (grade % 10 > 7 || grade % 10 == 0)
std::cout << '+'; }
if (grade > 90 && grade <= 100) {
std::cout << "You scored an A!\n";
if (grade % 10 <= 3)
std::cout << '-';
if (grade % 10 > 7 || grade % 10 == 0)
std::cout << '+'; }
}
works for the most part.... few bugs.... but i'm getting too nerd raged over this code to work on it any longer :D
Final Code:
[C++] grade.cpp - Pastebin.com
Bug free :) now time for a smoke
Code:#include <iostream>
#include <string>
int main()
{
int grade;
std::cout << "Enter your grade %: ";
std::cin >> grade;
if (grade <= 60) {
std::cout << "You scored an F\n"; }
if (grade > 61 && grade <= 70) {
std::cout << "You scored a D\n";
if (grade % 10 > 0 && grade % 10 <= 3)
std::cout << '-';
if (grade % 10 > 7 || grade % 10 == 0)
std::cout << '+'; }
if (grade > 70 && grade <= 80) {
std::cout << "You scored a C\n";
if (grade % 10 > 0 && grade % 10 <= 3)
std::cout << '-';
if (grade % 10 > 7 || grade % 10 == 0)
std::cout << '+'; }
if (grade > 80 && grade <= 90) {
std::cout << "You scored a B\n";
if (grade % 10 > 0 && grade % 10 <= 3)
std::cout << '-';
if (grade % 10 > 7 || grade % 10 == 0)
std::cout << '+'; }
if (grade > 90 && grade <= 100) {
std::cout << "You scored an A!\n";
if (grade % 10 > 0 && grade % 10 <= 3)
std::cout << '-';
if (grade % 10 > 7 || grade % 10 == 0)
std::cout << '+'; }
}
Looking at the code that you posted in post #19, consider this part:Quote:
Originally Posted by ferfy
Notice that you placed a closing brace on this line:Code:if (grade > 61 && grade <= 70) {
std::cout << "You scored a D\n"; }
if (grade % 10 <= 3) {
std::cout << '-'; }
if (grade % 10 > 7 || grade % 10 == 0) {
std::cout << '+'; }
This means that your later two if statements are not nested within the first one. As oogabooga noted in post #23, "Normal brace placement would make this more obvious".Code:std::cout << "You scored a D\n"; }
You fixed this in your code in post #26:
But now you removed the braces, which introduces the possibility of errors later if you should somehow need to make the bodies of the inner if statements more than one line. Also notice that you indented the inner if statements extra. This creates the illusion that they are somehow in a "more local" block of scope that the std::cout statement.Code:if (grade > 61 && grade <= 70) {
std::cout << "You scored a D\n";
if (grade % 10 <= 3)
std::cout << '-';
if (grade % 10 > 7 || grade % 10 == 0)
std::cout << '+'; }
For your final code, I note that you can simplify it. Notice that you repeat the code for '+' and '-'. With a little tweaking of the text to be printed, and excluding the case for 'F', you can have the code for '+' and '-' after the code to print the letter grade. This was the whole reason why you wanted to use modulo, if you recall :)
ah didn't know i could do that :D hahahaha
here's the simplified code:
thanks :) indentation is a little wacky... but mehCode:#include <iostream>
#include <string>
int main()
{
int grade;
std::cout << "Enter your grade %: ";
std::cin >> grade;
if (grade <= 60) {
std::cout << "You scored an F\n"; }
if (grade > 61 && grade <= 70) {
std::cout << "You scored a D\n"; }
if (grade > 70 && grade <= 80) {
std::cout << "You scored a C\n"; }
if (grade > 80 && grade <= 90) {
std::cout << "You scored a B\n"; }
if (grade > 90 && grade <= 100) {
std::cout << "You scored an A!\n"; }
if (grade % 10 > 0 && grade % 10 <= 3) {
std::cout << '-';
if (grade % 10 > 7 || grade % 10 == 0)
std::cout << '+'; }
}
my bad..... still was bugged... here's the new fix:
[C++] grade.cpp - Pastebin.com
Code:
- #include <iostream>
- #include <string>
- int main()
- {
- int grade;
- std::cout << "Enter your grade %: ";
- std::cin >> grade;
- if (grade <= 60) {
- std::cout << "You scored an F\n"; }
- if (grade > 60 && grade <= 70) {
- std::cout << "You scored a D\n"; }
- if (grade > 70 && grade <= 80) {
- std::cout << "You scored a C\n"; }
- if (grade > 80 && grade <= 90) {
- std::cout << "You scored a B\n"; }
- if (grade > 90 && grade <= 100) {
- std::cout << "You scored an A!\n"; }
- if (grade % 10 > 0 && grade % 10 <= 3)
- std::cout << '-';
- if (grade % 10 > 7 || grade % 10 == 0)
- std::cout << '+';
- }
it's still not efficient cuz i could use if elses.... but i really dont feel like revising it for the 30th time....x.x