Jump to content

Programming class need help!

grant N

What part are you looking help for?

Everything? Just the start? middle? End?

Thats the thing w/ programming, You need to learn it yourself, You need to put in the research and teach yourself.\

 

Offnote on coding in general 

Coding isn't something teachers teach you how to do

Its something you learn how to do from experience. You don't learn from another person telling you what to do, then you won't know what to do when your lost/confused.

You need to learn how to do it yourself, after school, learn when to use certain things, when not too.  

Now I'm no coding expert, However, I have a very wise friend who did try coding and he said that exact thing.

Link to comment
Share on other sites

Link to post
Share on other sites

first form out pseudocode so use words to describe what the program will do

 

Alt+MAlt+N

Link to comment
Share on other sites

Link to post
Share on other sites

can some one please help me with this?

 

quit your class already if u need help for this

Link to comment
Share on other sites

Link to post
Share on other sites

can some one please help me with this?

Do you want us to tell you what to type, or give you a general idea of what you have to do?

So thanks for reading guys, if this post sucked, I'm not sure what you can do, but if you liked it, go 'head and hit that like button, or maybe add me as a friend. Otherwise, go subscribe to LinusTechTips on YouTube, follow them on Twitch, follow @LinusTech on Twitter, and support them by using their affiliate code on Amazon, buying a cool T-shirt, or supporting them directly on this community forum.

Link to comment
Share on other sites

Link to post
Share on other sites

Can't exactly help you without "Demo0107"

We learn when we tinker.

Link to comment
Share on other sites

Link to post
Share on other sites

Anyway, here is an overview of what you have to do:

  1. Define some variables for what the user inputs, and whatever you want to calculate
  2. (I assume you are using the command line to do this, and don't want to do something with windows or whatever): Use cout statements to ask the user what their gallons, starting mileage, ending mileage.
  3. Use cin statements to let the user enter them, and to assign the values that they type to the variables from step 1
  4. Do some math to calculate the mileage.
  5. Use an if to check if the entered mileage is -1 and if so, have the program print out totals for the miles and gallons, calculate an average mpg, and then to return 0
  6. You should put all of this into a infinite loop so then it will run until the user enters -1 as the miles used, and will then return 0 after printing.

This program is sorta just testing your problem solving skills, as well as top down design etc.

 

A few notes: make sure you use #include iostream if you want to use cout and cin statements, as they won't work otherwise it won't work.

I would suggest making variables that represent the the values for starting mileage, ending mileage, diff in mileage, gallons used, total gallons, and total distance.

I probably am forgetting something, so think about it yourself.

So thanks for reading guys, if this post sucked, I'm not sure what you can do, but if you liked it, go 'head and hit that like button, or maybe add me as a friend. Otherwise, go subscribe to LinusTechTips on YouTube, follow them on Twitch, follow @LinusTech on Twitter, and support them by using their affiliate code on Amazon, buying a cool T-shirt, or supporting them directly on this community forum.

Link to comment
Share on other sites

Link to post
Share on other sites

You should prob explain what you need help with rather than posting a sideways picture that no one will read.

 

Agreed, I sure as hell am not going to bother reading that and trying to divine what it is exactly that you seem to be after. Show some effort and perhaps others may reciprocate.

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

Moved to Programming and Software Design. 

15" MBP TB

AMD 5800X | Gigabyte Aorus Master | EVGA 2060 KO Ultra | Define 7 || Blade Server: Intel 3570k | GD65 | Corsair C70 | 13TB

Link to comment
Share on other sites

Link to post
Share on other sites

Here, now someone might help without the fear of breaking their neck. I would help but I don't know C++

JsfGjxH.png

Link to comment
Share on other sites

Link to post
Share on other sites

get gallons used

if -1 exit program

else

get start mileage

get end mileage

mile driven = end - start

m/g = mile driven / gallons used

 

 

now code that in c++. might want to check that gallons isn't lower than zero and that it is actually a number.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

int main(int argc, const char * argv[]) {        float usedGallons = 0.0f;    int start = 0, end = 0;    int d = 0;    float m = 0.0f;        while(true)    {        std::cout << "Used gallons";        std::cin >> usedGallons;        if(usedGallons == -1)            break;        std::cout << "Start mileage:";        std::cin >> start;        std::cout << "End mileage:";        std::cin >> end;        d = end - start;        m = d / usedGallons;        std::cout << "Result: " << m << std::endl;    }        return 0;}

I wrote it fast and didn't test it but it should work.

Link to comment
Share on other sites

Link to post
Share on other sites

 

You just did this guys home work.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

It's what he wanted.

now he is gonna pass a class he has no idea about.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

I dont understand this is one of the eassiest things in C++ all you deal with is int main and cout/cin and a couple local variables.What help do you need? you want someone to write the code for you ? or some advice what is the problem? show us the code you tried to write so far and where you are stuck.

If you didnt try to solve it at all quit whatever you are doing, unless its highschool which i doubt?

Link to comment
Share on other sites

Link to post
Share on other sites

I dont understand this is one of the eassiest things in C++ all you deal with is int main and cout/cin and a couple local variables.What help do you need? you want someone to write the code for you ? or some advice what is the problem? show us the code you tried to write so far and where you are stuck.

If you didnt try to solve it at all quit whatever you are doing, unless its highschool which i doubt?

"all you deal with is int main and cout/cin and a couple local variables."

 

You wouldn't say that if you actually learned C++

Link to comment
Share on other sites

Link to post
Share on other sites

"all you deal with is int main and cout/cin and a couple local variables."

You wouldn't say that if you actually learned C++

We have programming classes at high school and we learned c++.However, we mainly do algorithmic. That's very interesting and quite challenging, depending on the problem. Still, the problem of the OP is really easy. It's just a loop, user input and a mathematical formula.

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
Share on other sites

Link to post
Share on other sites

int main(int argc, const char * argv[]) {        float usedGallons = 0.0f;    int start = 0, end = 0;    int d = 0;    float m = 0.0f;        while(true)    {        std::cout << "Used gallons";        std::cin >> usedGallons;        if(usedGallons == -1)            break;        std::cout << "Start mileage:";        std::cin >> start;        std::cout << "End mileage:";        std::cin >> end;        d = end - start;        m = d / usedGallons;        std::cout << "Result: " << m << std::endl;    }        return 0;}
I wrote it fast and didn't test it but it should work.
Probably want to throw a quick check in there to make sure that end is greater than start [emoji3]
Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×