I’m actually going crazy. After spending a lot of time working on Decision making (if-else, switch and …), I really cannot figure out the basic difference between iteration and decision making. In some problems, the tutor asks us to use “While” loop and “break”, instead of “if-else” and it makes me confused. Why???
Yes, yes, I know that it creates a loop, but the problem is that the debugger doesn’t say anything. The program seems to be very well-organized (0 warning, 0 errors). It takes 10 numbers and nothing… freezes! Oh thanks my goodness!
Do something or at least tell me what the heck is wrong with my program.
Let’s start from the first question: There’s a table about the grading structure including ten grades (A,A-,B+,B,B-,C+,C,C-,D+,D,F). One should key-in ten scores (0-100; all integers). We should write a program using a “do-while” loop to print out the grades for every score entered.
So we have ten scores (s1,s2,…,s10) and ten grades (as mentioned above). For every value (score) we key-in, it should decide whether the student should be awarded with (A,A-,…,F). Isn’t it “Decision making”? How to use a loop then?
Let’s solve it first. The second question is even screwier.
Can you gimme a hand mates?
Thanks a bunch
P.S. I’m using a reference book named “Programming in C++: Lessons and Applications” by Timothy B. D’Orazio, McGraw-Hill. This chapter (iteration) is not very well-written (too short to me). Any better suggestion?
Recommended Answers
Jump to Post... the debugger doesn’t say anything. The program seems to be very well-organized (0 warning, 0 errors). It takes 10 numbers and nothing… freezes! Oh thanks my goodness!
Do something or at least tell me what the heck is wrong with my program.) "0 warning, 0 errors" is coming …
Jump to Postif( ... ) { ... }
else { ... } is not a loop, it's a conditional block. It tests the logical expression in the ( ... ) and uses the result [true,false] to determine whether or not to execute a block of code:
if( [some logical condition is true] …
Jump to PostIt's Ok. I know the rules.
Apparently not well enough to add code tags
[code=cplusplus] // your code here
[/code]
Jump to PostThis one, on the other hand, ain't. It has nothing to do with increment, at least from what you'd get from the first look.
Then you need to take a second look.
Instead of 10 independent variables to hold the scores, how about a 10-element array:
int scores[10]
Define …
Jump to PostAll you have to do is put that code in a loop. Simple.
for(i = 0; i < 10; i++) { if( score[i]>79 && score[i]<101 ) { cout<<i+1<<"\t"<<score[i]<<"\t\tA"<<endl; outfile<<i+1<<"\t"<<score[i]<<"\t\tA"<<endl; } else if( score[i]>74 && score[i]<80) { cout<<i+1<<"\t"<<score[i]<<"\t\tA-"<<endl; outfile<<i+1<<"\t"<<score[i]<<"\t\tA-"<<endl; } else if (score[i]>69 && score[i]<75) { cout<<i+1<<"\t"<<score[i]<<"\t\tB+"<<endl; outfile<<i+1<<"\t"<<score[i]<<"\t\tB+"<<endl; …
All 30 Replies
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.