home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Join TechIMO for Free!
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Reply Get bargains at  »  Dealighted.com
 
Thread Tools
Currently Active Users: 2786
Discussions: 186,609, Posts: 2,227,070, Members: 230,244
Free Scan: Update Your PC's Outdated Drivers to Optimize Performance
Old July 28th, 2008, 02:01 PM   Digg it!   #1 (permalink)
Junior Member
 
Join Date: Jul 2008
Posts: 2
Need Help with C - School project

Hi guys

I was given this problem for my summer assignment

Write a program to simulate a cash register change calculator. Allow the user to
enter a purchase price of up to 100 dollars. Then determine the best change to
give back for a $100 bill. Print the results to the screen as below, with no zero

Now i am new to programming but have a couple of books on C so i thought i would give it my best shot. Here was what i have so far. If anyone could look over it and correct any mistakes or advice me on what to do that would be greatly appreciated. also if anyone could please recommend a good compiler package, that would be great also. Thank you for your time.

//================================================== ==========================
// Name : cash.cpp
// Author : Chris Thorne
// Version :1
// Copyright : Your copyright notice
// Description : Summer assignment
//================================================== ==========================


#include <stdio.h>

int main()
{
int dollar ; /* input – this will be 100*/
int change ; /* input – change that is needed*/
int one = 1 ; /* output*/
int five = 5 ; /*output */
int twenty = 20 ; /* output*/
int round1
int round2
int round3

/* asking how much money was given*/
Printf("Hello, please type in how much money was present> \n“);
Scanf("%d", &dollar)
Printf("Thank you, you entered %d dollars 0 cents. \n” , dollars) ;
Printf(" Please enter the amount of change needed > \n”);
Scanf("%d”, &change) ;
Printf("Thank you, you owe the customer %d dollars 0 cents. \n “ , change) ;
Printf("Your change is $ %d. \n")
/* now calculating the change*/
if (change < 20)
{
printf("0 $20 bill. \n");
if (change >= 15)
{
Printf("3 $5 bills. \n")
}
else if ((change >= 10) && (<15))
{
printf("2 $5 bills. \n")
}
else if ((change >= 5)&& (<10))
{
printf ("1 $5 bill.")
}
else if (change < 5)
{
printf ("0 $5 bill.")
}
}

else if ((change >= 20) && (<40))
{
printf('1 $20 bill');
round1 = change - twenty ;
if (round1 >= 15)
{
Printf("3 $5 bills. \n")
}
else if ((round1 >= 10) && (<15))
{
printf("2 $5 bills. \n")
}
else if ((round1 >= 5)&& (<10))
{
printf ("1 $5 bill. \n")
}
else if (round1 < 5)
{
printf ("o $5 bill. \n")
}
}


Last edited by chrispringle : July 28th, 2008 at 02:08 PM. Reason: make it easier to read
chrispringle is offline   Reply With Quote
TechIMO.com Ads - Login or register for less ads.
How many errors does your computer have?

You no longer need to guess! This free stability scan and registry cleaner download will give you a complete diagnosis of your Windows registry, identifying errors and conflicts.

FREE instant scan


Guest, Register Free! to remove this ad and get your tech support questions answered in minutes!
Old July 28th, 2008, 03:22 PM     #2 (permalink)
Real gangstas sip on Yacc
 
jkrohn's Avatar
 
Join Date: Oct 2001
Location: Suckas-ville
Posts: 4,540
Send a message via ICQ to jkrohn Send a message via AIM to jkrohn Send a message via Yahoo to jkrohn
Well you are supposed to simulate a cash register, so I would imagine it would go more like this.

"Please enter the cost of the items"
"Please enter how much money they gave you"

Calculate how much change to give back
Calculate what bills/coins to use.

Also it appears you are not doing coins which I imagine would be a requirement.

For calculating how many of each bill start at the biggest and work down.
If the total is greater than the bill, use integer division to see how many of that bill to give them. Then set the remaining total to be total modulus bill and continue on with smaller bills.
__________________
Signatures blow hard
If your signature contains an ad of any kind, congratulations, you're on my ignore list.

jkrohn is online now   Reply With Quote
Old July 30th, 2008, 06:31 PM     #3 (permalink)
Ultimate Member
 
Rootstonian's Avatar
 
Join Date: Mar 2005
Location: Out of my mind
Posts: 2,742
Send a message via AIM to Rootstonian
I like to know what the teacher is covering at the point of the assignment.

Are you going over loops (for, while, if/else)?

Are you going over recursion?

Did he introduce you to the mod operator?

Not sure what your code is doing...what if my purchase was a penny? You owe me $99.99


Last edited by Rootstonian : July 30th, 2008 at 06:33 PM.
Rootstonian is offline   Reply With Quote
Old July 31st, 2008, 01:36 AM     #4 (permalink)
Junior Member
 
Join Date: Jul 2008
Posts: 2
no its the summer assignment, so i have never met the teacher.
this is my first time as well, so i probably did it a long and hard way.


The sheet said just to use dollar intervals. and to only use 1,5,20
I have the completed code now anyways. And it works great :]

Code:
#include <stdio.h>
int
main(void)
{
    int  dollar; /* input – this will be 100*/
    int change; /* input – change that is needed*/
    int circle1;/* 3 $5 bills*/
    int circle5; /* 2 $5 bills*/
    int circle3;/* 1 $5 bills*/
    int circle4;/* 0 $5 bills*/

    /* asking how much money was given*/
printf("Hello, please type in how much money was present> \n");
scanf("%d", &dollar);
printf("Thank you, you entered %d dollars 0 cents. \n", dollar);
printf(" Please enter the amount of change needed  > \n");
scanf("%d", &change);
printf("Thank you, you owe the customer %d dollars 0 cents. \n", change) ;
printf("Your change is $ %d. \n", change) ;
/* now calculating the change*/

    if (change < 20)
        {
            printf("0 $20 bill. \n");
            if (change >= 15)
                {
                    printf("3 $5 bills. \n");
                    circle1 = change - 15;
                    printf("%d $1 bill(s). \n", circle1 );

                }
            else if ((change >= 10) && ( change <15))
                {
                    printf("2 $5 bills. \n");
                    circle5 = change - 10;
                    printf("%d $1 bill(s). \n", circle5 );
                }
            else if ((change >= 5)&& ( change <10))
                {
                    printf ("1 $5 bill. \n");
                    circle3 = change - 5;
                    printf("%d $1 bill(s). \n", circle3 );
                }
            else if (change < 5)
                            {
                    printf ("0 $5 bill. \n");
                    circle4 = change;
                    printf("%d $1 bill(s). \n", circle4);
                            }
        }
    else if ((change >= 20) && ( change<40))
            {
                printf("1 $20 bill. \n");
                change = change ;
                if (change >= 35)
                    {
                        printf("3 $5 bills. \n");
                        circle1 = change -35 ;
                        printf("%d $1 bill(s). \n", circle1 );
                    }
                else if ((change >= 30) && (change<35))
                    {
                        printf("2 $5 bills. \n");
                        circle5 = change - 30;
                        printf("%d $1 bill(s). \n", circle5 );
                    }
                else if ((change >= 25)&& (change<30))
                    {
                        printf ("1 $5 bill. \n");
                        circle3 = change - 25 ;
                        printf("%d $1 bill(s). \n", circle3);
                    }
                else if (change < 25)
                    {
                        printf ("0 $5 bill. \n");
                        circle4 = change - 20;
                        printf( "%d $1 bill(s). \n", circle4);
                    }
            }
    else if ((change >= 40) && ( change <60))
            {
                printf("2 $20 bills. \n");

                if (change >= 55)
                    {
                        printf("3 $5 bills. \n");
                        circle1 = change - 55;
                        printf("%d $1 bill(s). \n", circle1 );
                    }
                else if ((change >= 50) && ( change <55))
                    {
                        printf("2 $5 bills. \n");
                        circle5 = change - 50;
                        printf("%d $1 bill(s). \n", circle5 );
                    }
                else if ((change >= 45)&& (change <50))
                    {
                        printf ("1 $5 bill. \n");
                        circle3 = change - 45;
                        printf("%d $1 bill(s). \n",circle3);
                    }
                else if (change < 45)
                    {
                        printf ("0 $5 bill. \n");
                        circle4 = change - 40;
                        printf("%d $1 bill(s). \n",circle4);
                    }
            }
    else if ((change >= 60) && (change <80))
                {
                    printf("3 $20 bills. \n");

                    if (change >= 75)
                        {
                        printf("3 $5 bills. \n");
                        circle1 = change - 75;
                        printf("%d $1 bills. \n", circle1 );
                        }
                    else if ((change >= 70) && (change <75))
                        {
                        printf("2 $5 bills. \n");
                        circle5 = change - 70;
                        printf("%d $1 bill(s). \n", circle5 );
                        }
                    else if ((change >= 65)&& (change <70))
                        {
                        printf ("1 $5 bill. \n");
                        circle3 = change - 65;
                        printf("%d $1 bill(s). \n",circle3);
                        }
                    else if (change < 65)
                        {
                        printf ("0 $5 bill. \n");
                        circle4 = change - 60;
                        printf( "%d $1 bill(s). \n", circle4);

                        }
                }
    else if ((change >= 80) && ( change <100))
                {
                    printf("4 $20 bills. \n");

                    if (change >= 95)
                        {
                        printf("3 $5 bills. \n");
                        circle1 = change - 95;
                        printf("%d $1 bill(s). \n",circle1);
                        }
                    else if ((change >= 90) && (change <95))
                        {
                        printf("2 $5 bills. \n");
                        circle5 = change - 90;
                        printf("%d $1 bill(s). \n", circle5 );
                        }
                    else if ((change >= 85) && (change <90))
                        {
                        printf ("1 $5 bill. \n");
                        circle3 = change - 85;
                        printf("%d $1 bill(s). \n",circle3);
                        }
                    else if (change < 85)
                        {
                        printf ("0 $5 bill. \n");
                        circle4 = change - 80;
                        printf( "%d $1 bill(s). \n", circle4);
                        }
                }
    return(0);



}
#include <stdio.h>
int
main(void)
{
    int  dollar; /* input – this will be 100*/
    int change; /* input – change that is needed*/
    int circle1;/* 3 $5 bills*/
    int circle5; /* 2 $5 bills*/
    int circle3;/* 1 $5 bills*/
    int circle4;/* 0 $5 bills*/

    /* asking how much money was given*/
printf("Hello, please type in how much money was present> \n");
scanf("%d", &dollar);
printf("Thank you, you entered %d dollars 0 cents. \n", dollar);
printf(" Please enter the amount of change needed  > \n");
scanf("%d", &change);
printf("Thank you, you owe the customer %d dollars 0 cents. \n", change) ;
printf("Your change is $ %d. \n", change) ;
/* now calculating the change*/

    if (change < 20)
        {
            printf("0 $20 bill. \n");
            if (change >= 15)
                {
                    printf("3 $5 bills. \n");
                    circle1 = change - 15;
                    printf("%d $1 bill(s). \n", circle1 );

                }
            else if ((change >= 10) && ( change <15))
                {
                    printf("2 $5 bills. \n");
                    circle5 = change - 10;
                    printf("%d $1 bill(s). \n", circle5 );
                }
            else if ((change >= 5)&& ( change <10))
                {
                    printf ("1 $5 bill. \n");
                    circle3 = change - 5;
                    printf("%d $1 bill(s). \n", circle3 );
                }
            else if (change < 5)
                            {
                    printf ("0 $5 bill. \n");
                    circle4 = change;
                    printf("%d $1 bill(s). \n", circle4);
                            }
        }
    else if ((change >= 20) && ( change<40))
            {
                printf("1 $20 bill. \n");
                change = change ;
                if (change >= 35)
                    {
                        printf("3 $5 bills. \n");
                        circle1 = change -35 ;
                        printf("%d $1 bill(s). \n", circle1 );
                    }
                else if ((change >= 30) && (change<35))
                    {
                        printf("2 $5 bills. \n");
                        circle5 = change - 30;
                        printf("%d $1 bill(s). \n", circle5 );
                    }
                else if ((change >= 25)&& (change<30))
                    {
                        printf ("1 $5 bill. \n");
                        circle3 = change - 25 ;
                        printf("%d $1 bill(s). \n", circle3);
                    }
                else if (change < 25)
                    {
                        printf ("0 $5 bill. \n");
                        circle4 = change - 20;
                        printf( "%d $1 bill(s). \n", circle4);
                    }
            }
    else if ((change >= 40) && ( change <60))
            {
                printf("2 $20 bills. \n");

                if (change >= 55)
                    {
                        printf("3 $5 bills. \n");
                        circle1 = change - 55;
                        printf("%d $1 bill(s). \n", circle1 );
                    }
                else if ((change >= 50) && ( change <55))
                    {
                        printf("2 $5 bills. \n");
                        circle5 = change - 50;
                        printf("%d $1 bill(s). \n", circle5 );
                    }
                else if ((change >= 45)&& (change <50))
                    {
                        printf ("1 $5 bill. \n");
                        circle3 = change - 45;
                        printf("%d $1 bill(s). \n",circle3);
                    }
                else if (change < 45)
                    {
                        printf ("0 $5 bill. \n");
                        circle4 = change - 40;
                        printf("%d $1 bill(s). \n",circle4);
                    }
            }
    else if ((change >= 60) && (change <80))
                {
                    printf("3 $20 bills. \n");

                    if (change >= 75)
                        {
                        printf("3 $5 bills. \n");
                        circle1 = change - 75;
                        printf("%d $1 bills. \n", circle1 );
                        }
                    else if ((change >= 70) && (change <75))
                        {
                        printf("2 $5 bills. \n");
                        circle5 = change - 70;
                        printf("%d $1 bill(s). \n", circle5 );
                        }
                    else if ((change >= 65)&& (change <70))
                        {
                        printf ("1 $5 bill. \n");
                        circle3 = change - 65;
                        printf("%d $1 bill(s). \n",circle3);
                        }
                    else if (change < 65)
                        {
                        printf ("0 $5 bill. \n");
                        circle4 = change - 60;
                        printf( "%d $1 bill(s). \n", circle4);

                        }
                }
    else if ((change >= 80) && ( change <100))
                {
                    printf("4 $20 bills. \n");

                    if (change >= 95)
                        {
                        printf("3 $5 bills. \n");
                        circle1 = change - 95;
                        printf("%d $1 bill(s). \n",circle1);
                        }
                    else if ((change >= 90) && (change <95))
                        {
                        printf("2 $5 bills. \n");
                        circle5 = change - 90;
                        printf("%d $1 bill(s). \n", circle5 );
                        }
                    else if ((change >= 85) && (change <90))
                        {
                        printf ("1 $5 bill. \n");
                        circle3 = change - 85;
                        printf("%d $1 bill(s). \n",circle3);
                        }
                    else if (change < 85)
                        {
                        printf ("0 $5 bill. \n");
                        circle4 = change - 80;
                        printf( "%d $1 bill(s). \n", circle4);
                        }
                }
    return(0);



}

Last edited by chrispringle : July 31st, 2008 at 01:40 AM.
chrispringle is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
School Project: What to Do? uncle_jimbo IMO Community 12 November 9th, 2005 03:42 AM
Help with School Project Jokerswild General Tech Discussion 12 July 13th, 2005 01:42 PM
School project using MS Powerpoint. Mr.Macintosh General Tech Discussion 3 November 17th, 2004 11:20 PM
School project. PyroSama Webmastering and Programming 24 March 12th, 2003 09:53 PM
help on school project! eclipsera General Tech Discussion 10 January 8th, 2003 08:00 PM

Most Active Discussions
Is It Just Me? (536)
Misery Loves Company... (1849)
Why Does the MOON Grow Bigger as It.. (18)
heatsink issue (10)
New Mobo (18)
UPGRADING C/D DRIVE TO 250GB & .. (14)
1 internet. 1 house. 3 computer. ho.. (13)
Is This A Compatible Gaming PC? (18)
SSD's, RAID, and External Backup (7)
Recent Discussions
webcam sharing (0)
help! jumbled text and computer.. (1)
Scanning problem (4)
DFI socket 939 board acting up (5)
Building my first PC and need s.. (2)
32 or 64 bit vista (4)
Big problem with my PC (2)
system restore 'next' button wo.. (2)
firewall (1)
FS: Dell 6000 laptop, modded 36.. (2)
Apple iPod touch 16 GB $200 (4)
Six 28-Disc Cross Design Black .. (4)


All times are GMT -4. The time now is 12:49 PM.
TechIMO Copyright 2008 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28