Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

yoshimitsu15

YAY! gotta compiler!

This topic is 5991 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I gots me a compiler now! Dev C++ I like it so far. But I have a few q''s for the pro''s. Ok I went to this site, and it had tutes on C++. So I was reading one of them, and I tried out the first program I would ever make. I made (get''s teary) the computer say (in text not in speach) SNOOOORRRXXX on a DOS window... Wow, man, wow... lol Anyway, that worked and I was sooo happy. Yep, I''m simple. Now, I have this problem. I went to the next part where the writer showed and example of code so i copied it (not copy and paste just typed it) into my compiler just to get the feel for typing code. Well, it wasn''t right. So I messed with it for a bit, and I made it work. But it doesn''t do what is sposed to do. For example - It asks in a very dull barfy DOS window the enter the transaction number and the number of days the video was rented (video rental store thingamahgigger). SO What it''s SPOSED to do is You put in... say (only 2 or 3 cuz that''s what the movies cost) 2 and then you put in.... (number of days) 3 then it''s sposed to add those up and poof there yah have it.. The result. Which should be.... WOW! 6.... Here''s the code for those who want to know that is.....#include <iostream.h> int main() { int total_dollars = 0; int total_days_at_3_dollars = 0; int total_days_at_2_dollars = 0; int transaction_code = 0; int days_for_one_video = 0; do { if(transaction_code==2) total_days_at_2_dollars+=days_for_one_video; if(transaction_code==3) total_days_at_3_dollars+=days_for_one_video; cout<<"Please enter a transaction code and number of days a video was rented: "; cin>>transaction_code>>days_for_one_video; }while(transaction_code!=0); return 0; } So what''s wrong? If you could find out.. I will be greatful. How now brown cow?

Share this post


Link to post
Share on other sites
Advertisement
There''s nothing wrong with this code.

However, at no point are you actually displaying the values that you have totaled. If you want to do that, replace this:


cout<<"Please enter a transaction code and number of days a video was rented: ";


with this:


cout << "Total number of days at two dollars/day: " << total_days_at_2_dollars << endl;
cout << "Total number of days at three dollars/day: " << total_days_at_3_dollars << endl;
cout<<"Please enter a transaction code and number of days a video was rented: ";

Share this post


Link to post
Share on other sites
Not to bash in any way, but I thought noone used the do...while.. It seems complicated to me. Isn''t it easier to just do a while?

ERJO

Share this post


Link to post
Share on other sites
The difference between do .. while and just while is that a do..while loop always gets executed at least once. This can be useful, especially in situations like this where the user should at least input one number.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!