YAY! gotta compiler!

Started by
3 comments, last by yoshimitsu15 22 years, 1 month ago
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?
How now brown cow?
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: "; 
You don't need to vote for the "lesser of two evils"! Learn about Instant Runoff Voting, the simple cure for a broken democracy!
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
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.
Thanks for the replys guys!
I appreciate it!
^^

How now brown cow?
How now brown cow?

This topic is closed to new replies.

Advertisement