C++ Learning Community Forum
August 01, 2010, 02:50:02 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Hello. Smiley
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: vending machine?  (Read 1348 times)
oulyt
C++ Freak
***
Posts: 340



View Profile
« on: October 25, 2008, 09:28:42 PM »

this is sorta a vending machine program i had to do for my C++ class. originally we just needed to make it convert a cent amount to quarter dimes nickel and penny. i just fixed it up a bit to make it work better then what the teacher wanted. though i post it.

Code
GeSHi (cpp):
/* by oulyt
*   Cent convert Project
*   10/22/08
*   Converts an entered amount
*   of cents to quarter, dime,
*   nickles and pennies
*/

 
#include <iostream>
#include <cctype>
 
using namespace std;
 
int main()
 
{
   int cent, penny, dime, nickle, quarter;
 
   char z = 'y';
 
   while(z=='y')
   {
 
   cout << "Enter a number of cents between 1 and 99 \n";
   cin >> cent;
 
   if ( cent > 0 && cent < 100 )
   {
   quarter = cent / 25;
   cent %= 25;
   dime = cent / 10;
   cent %= 10;
   nickle = cent / 5;
   cent %= 5;
   penny = cent / 1;
   cent %= 1;
 
   cout << "The amount of cents you entered is equal to \n";
   cout << quarter << " quarter(s)\n";
   cout << dime << " dime(s)\n" << nickle << " nickle(s)\n";
   cout << penny << " penny(s) "<< endl;
 
   }
 
   else
   {
       cerr << "Please enter an amount between 1 and 99" << endl;
 
   }
       cout << "\nTry again? (y/n)";
       cin >> z;
       z = tolower(z);
   }
}
Created by GeSHI 1.0.7.18

this uses everything i learned so far except loops
« Last Edit: November 23, 2008, 12:43:06 AM by oulyt » Logged
ih8censorship
Megalomaniac!!!
Administrator
C++ guru
*****
Posts: 1236



View Profile
« Reply #1 on: October 25, 2008, 10:32:02 PM »

What if a users capslock is on and they hit the y key? Maybe convert the input to lowercase just in case -> http://www.cprogramming.com/fod/tolower.html Just a suggestion, and that sort of thinking can help later on as well  Wink

Also, I know the code blocks have issues on this board relating to displaying indentation correctly, but I want to be sure you at least understand how to indent and why it is important . This should give you a general idea of what I'm talking about http://www.chris-lott.org/resources/cstyle/CppCodingStandard.html#indent And again I apologize if your code was indented neatly and i didnt see it because of what the board did to it, but i just want to be sure you know this  Smiley
Logged

PC==perfect_companion

Knowledge cannot come packaged and predigested; it must be chewed over carefully before swallowed.

What have you tried?
oulyt
C++ Freak
***
Posts: 340



View Profile
« Reply #2 on: October 26, 2008, 01:34:05 AM »

What if a users capslock is on and they hit the y key? Maybe convert the input to lowercase just in case -> http://www.cprogramming.com/fod/tolower.html Just a suggestion, and that sort of thinking can help later on as well  Wink

Also, I know the code blocks have issues on this board relating to displaying indentation correctly, but I want to be sure you at least understand how to indent and why it is important . This should give you a general idea of what I'm talking about http://www.chris-lott.org/resources/cstyle/CppCodingStandard.html#indent And again I apologize if your code was indented neatly and i didnt see it because of what the board did to it, but i just want to be sure you know this  Smiley

thanks alot. i'll convert the input to lowercase. as far is the indent stuff i did it that way myself. i didnt know where was some special was i needed to do it. im gonna read that stuff over and fix mine. thanks alot Smiley

--
ok i fixed it to take in Captial Y.

as for the indent >.> thats gonna take longer. i cant seem to get it the way the site is showing me. i think i got it right in my compiler. just wont update it right now till i think i got it right =/
« Last Edit: October 26, 2008, 01:46:59 AM by oulyt » Logged
death
http://aroymart.com rocks!
Nerd
****
Posts: 82



View Profile WWW
« Reply #3 on: February 26, 2009, 10:42:31 PM »

this is cool i like it


it's ok that i'm messing around changing it ifi don't publicly display it right? i want to see if i understand any of this
Logged

I finally learned how to set up openGL!
Seismosaur
ez::esS::AI::Entity::Brain
C++ Freak
***
Posts: 461



View Profile
« Reply #4 on: February 26, 2009, 11:55:41 PM »

Lucky. If I ever made an improvment on any of the web sites we do in my Web Design class my teacher would fail me =/
Logged

death
http://aroymart.com rocks!
Nerd
****
Posts: 82



View Profile WWW
« Reply #5 on: February 27, 2009, 12:37:25 AM »

this is just to see what i understand myself, i have no teacher except C++ for dummies
Logged

I finally learned how to set up openGL!
Seismosaur
ez::esS::AI::Entity::Brain
C++ Freak
***
Posts: 461



View Profile
« Reply #6 on: February 27, 2009, 01:57:45 AM »

Whoops.

I was addressing ouylt.
Logged

oulyt
C++ Freak
***
Posts: 340



View Profile
« Reply #7 on: March 01, 2009, 01:21:30 AM »

really? thats kinda messed up. my teacher dosnt mind. as long as you dont start giving your code away to the other kids. if you ahead stick to being ahead on your own  programs he said. well something like that
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!