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 PostIt's Ok. I know the rules.
Apparently not well enough to add code tags
[code=cplusplus] // your code here
[/code]
Jump to Postif grade is declared as an int then you need to typecast it when printing it
cout << (char)grade
It might be cleaner if you had an array of grades similar to the scores so that you could figure out all the grades first and then print them in a …
Jump to PostOk, normally wouldn't do it but this thread is getting pretty long and you have tried pretty hard. Here is how I would code it.
#include <iostream> #include <string> using namespace std; struct grades { int score; string grade; }; int lower_limits[10] = { 80, 75, 70, …
Jump to PostThanks for your patience, but we cannot use "string" and "struct" yet.
.replace string with character arrays and replace the struct with two arrays, one array of ints and the other of charcter arrays.
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.