Hi,
I am not sure if this an appropriate place to post a request for help solving logic problems. I am in an intro to programming class and am struggling with the basic logic problems. I am understanding the concepts of how to put together a program (modules, decision structures, loops, etc.), but none of that does me any good if I can't set the problem up in first place. Any suggestions are greatly appreciated.

EHarrell

What is the issue you are having exactly? Is it an assignment you have to complete? Post specifics so we can know what you are needing help with.

Issue: Your fellow students need help. This is their first year in college and they need to determine how many hours they need to study to get good grades.

Study hours per week / Grade
5 / A
4 / B
3 / C
2 / D
0 / F

The user enters either the number of hours they plan on studying per week or the grade they want based on the number of creadit hours they enter.

The program displays the user's name, number of credits, total number of study hours, and grade they should expect to receive.

if( user enters 5)

 print A

else if( user enters 4)

 print B

else if( user enters 3)

 print C

 //etc

Simplest logic for above problem. And Hi ! Welcome to daniweb.

Hey, I would do this using a SWITCH statement, over an if statement - If I'm honest.

I haven't completeled this, but, look at this logic.. It might help you. Re-write the code for your own use, don't just use it!

#include <iostream>

using namespace std;

int hoursToStudy(char grade)
{
    switch(grade)
    {
        case 'A':
            return 5;
        break;

        case 'B':

        break;

        case 'C':

        break;

        case 'D':

        break;

        case 'F':

        break;

        default: 
        cout << "Cannot define the grade";
        break;  

    }
}

int main(int argc, char *argv[]) {
    cout << hoursToStudy('A'); // prints 5
}

Logic is pretty simple :)!

Hi NP Complete and Phorce, Thank you both for your answers. I know this may seem very simple to you all, but for someone who is just starting off in the world of programming, there is a lot of ground to cover in a short period of time (one semester) to get the hang of thinking in a new way. I appreciate your patience.

@eharrell - Everyone had to learn somewhere (Even us) :) and in respect, we're all still learning hence why some of us are on here!

You should start writing out the steps on paper, asking how you would do it and try it.. The worst that can happen is a few compiler errors!

Good luck and keep posting on the forums - it's a great way to learn :)!

You have to be able to analyze the problem and pull out its important ideas. For example:

Issue: Your fellow students need help. This is their first year in college and

Who cares. Not part of the real problem...

they need to determine how many hours they need to study to get good grades.

Here is the problem statement. It's describes what needs to be done.

Study hours per week / Grade
5 / A
4 / B
3 / C
2 / D
0 / F

Here's the data necessary to determine the answer to the above question.

The user enters either the number of hours they plan on studying per week or the grade they want based on the number of creadit hours they enter.

The inputs required to process the data above.

The program displays the user's name, number of credits, total number of study hours, and grade they should expect to receive.

Additional inputs necessary for the output of the final solution have been added. Some is just bookkeeping (name). Some is the input for the solution (study hours or grade). The rest become the calculated values (grade or study hours) depending on the input.

In this case since there are 2 possible inputs (a letter for GRADE or a number for STUDY HOURS), there are two different calculations that need to be considered. Therefore a decision needs to be made after the input so that the proper task is performed.

Now armed with all that, start laying out the steps in a logical (obvious) order.

Steps are
determine the input entered
calculate grade
input name
calculate study hours
output the results
input grade or study hours

Put the steps in the order you need to accomplish the job. Keep in mind what needs to be available before each step is accomplished.

Now it's your turn -- you take it from here.

Hi WaltP. Thank you so much for your detailed response. It was exactly what I was looking for. I submitted my homework project last night - hopefully my raptor file, hierarchy chart, pseudocode and test data will be sufficient. Thanks again.

@eharrell- I am glad you managed to complete your work. We are all learning here, but one thing I find great is that people in this forum are always helpful towards those who show and demonstrate that they have done the effort and the work.

Good Luck!

Hi Geli19, I am proud to say that I have a 95.3 average in the class so far. I got an 89 on my first big test. Two more to go and then I am on to SQL in the spring. I am really enjoying learning and am so glad to have access to such a great group of people.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.