Question

I'm having trouble understanding pointers in my c programming class. I posted the pointer assignment below....

I'm having trouble understanding pointers in my c programming class. I posted the pointer assignment below. If you could leave comments pointing out where pointers are used it would be much appreciated!

-----------------------------------------------------------------------------------------------------------------------------------

Write a complete C program for an automatic teller machine that dispenses money. The user should enter the amount desired (a multiple of 10 dollars) and the machine dispenses this amount using the least number of bills. The bills dispenses are 50s, 20s, and 10s. Write a function that determines how many of each kind of bill to dispense.

When writing your function begin to pass your variables using pointers (or rather "pointing" to your data". Use the TimeSpace program example attached as you need to.

------------------------------------------------------------------------------------------------------------------------

This is the TimeSpace program.

#include <stdio.h>



void timer(int,int *,int *,int *); // * pointer, capable of holding an address
void print_results(int,int,int,int);
void explanation();

int main()
{
        int total_secs,hours,minutes,seconds;
        
        explanation();
        
        printf("How may total seconds to convert?\n");
        scanf("%d",&total_secs);
        
        timer(total_secs,&hours,&minutes,&seconds);//& indicates address of
        
        print_results(total_secs,hours,minutes,seconds);
                
        return 0;
}

void print_results(int ts, int h, int m, int s)
{
        printf("Total Seconds Entered: %8d\n",ts);
        printf("Hours                : %8d\n",h);
        printf("Minutes              : %8d\n",m);
        printf("Seconds              : %8d\n",s);
}


void timer(int ts,int *h,int *m, int *s)//* indicates a variable than hold an address
{
        *h=ts/3600;
        ts=ts%3600;
        *m=ts/60;
        ts=ts%60;
        *s=ts;
}


void explanation()
{
        printf("Give me a total number of seconds\n");
        printf("and I will tell you how many \n");
        printf("hours, minutes, and seconds it is.\n\n");
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>

void count(int* a,int* b,int* c,int* amt)
{
*a= *amt/50;
*amt=*amt%50;
*b=*amt/20;
*amt=*amt%20;
*c=*amt/10;
}

int main()
{
int amt;
scanf("%d",&amt);
  
int a=0; //stores no. of 50 bills
int b=0; //stores no. of 20 bills
int c=0; //stores no. of 10 bills
  
count(&a,&b,&c,&amt);
  
printf("No. of $50 Bills:%d \nNo. of $20 Bills:%d \nNo. of $10 Bills:%d",a,b,c); //prints no. of bills of each type
}

Add a comment
Know the answer?
Add Answer to:
I'm having trouble understanding pointers in my c programming class. I posted the pointer assignment below....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a complete C program for an automatic teller machine that dispenses money. The user should...

    Write a complete C program for an automatic teller machine that dispenses money. The user should enter the amount desired (a multiple of 10 dollars) and the machine dispenses this amount using the least number of bills. The bills dispenses are 50s, 20s, and 10s. Write a function that determines how many of each kind of bill to dispense. When writing your function begin to pass your variables using pointers (or rather "pointing" to your data". Use the TimeSpace program...

  • C++ PROGRAMMING Hi! My assignment prompt is below. What I'm having the most trouble understanding is...

    C++ PROGRAMMING Hi! My assignment prompt is below. What I'm having the most trouble understanding is where the shapes are being stored. I'm assuming an array, but I'm not sure how sizing would work. Any help is appreciated, thanks! I have also attached the .h file we must use. Prompt: The goal of HW2 is to implement classes representing shapes. A given program will use this class to create shapes at arbitrary locations in the x-y plane and move them....

  • Hi!, having trouble with this one, In this class we use visual studio, C++ language --------------------------------------------------------------...

    Hi!, having trouble with this one, In this class we use visual studio, C++ language -------------------------------------------------------------- Exercise #10 Pointers - Complete the missing 5 portions of part1 (2 additions) and part2 (3 additions) Part 1 - Using Pointers int largeArray (const int [], int); int largePointer(const int * , int); void fillArray (int * , int howMany); void printArray (const char *,ostream &, const int *, int howMany); const int low = 50; const int high = 90; void main()...

  • This is done in c programming and i have the code for the programs that it wants at the bottom i ...

    This is done in c programming and i have the code for the programs that it wants at the bottom i jut dont know how to call the functions Program 2:Tip,Tax,Total int main(void) {    // Constant and Variable Declarations    double costTotal= 0;    double taxTotal = 0;    double totalBill = 0;    double tipPercent = 0;    // *** Your program goes here ***    printf("Enter amount of the bill: $");    scanf("%lf", &costTotal);    printf("\n");    // *** processing ***    taxTotal = 0.07 * costTotal;    totalBill...

  • I'm having with my C program whenever i insert numbers it keeps outputting zeros here's the...

    I'm having with my C program whenever i insert numbers it keeps outputting zeros here's the code: #include<stdio.h> int main(void) {    int weeklyhours;    double hourlyrate;    double grosspay;    double netpay;    double federal;    double state;    double FICA;    double Medicare;    grosspay= weeklyhours * hourlyrate;    federal = grosspay * 0.1;    state = grosspay * 0.06;    FICA = grosspay * 0.062;    Medicare = grosspay * 0.0145;    netpay = grosspay - (federal...

  • C++ Error. I'm having trouble with a pointer. I keep getting the error "Thread 1: EXC_BAD_ACCESS...

    C++ Error. I'm having trouble with a pointer. I keep getting the error "Thread 1: EXC_BAD_ACCESS (code=1, address=0x18)" The objective of the assignment is to revise the public method add in class template LinkedBag so that the new node is inserted at the end of the linked chain instead of at the beginning. This is the code I have: linkedBag-driver.cpp BagInterface.hpp LinkedBag.hpp Node.hpp int main) LinkedBag<string> bag; cout << "Testing array-based Set:" << endl; cout << "The initial bag is...

  • Hello, I am having trouble with a problem in my C language class. I am trying...

    Hello, I am having trouble with a problem in my C language class. I am trying to make a program with the following requirements: 1. Use #define to define MAX_SIZE1 as 20, and MAX_SIZE2 as 10 2. Use typedef to define the following struct type: struct {     char name[MAX_SIZE1];     int scores[MAX_SIZE2]; } 3. The program accepts from the command line an integer n (<= 30) as the number of students in the class. You may assume that the...

  • C Programming Question Hi, I have the following code and in my submission I'm supposed to...

    C Programming Question Hi, I have the following code and in my submission I'm supposed to only include function definitions (i.e. implementations) in the file. However, I'm not NOT required to write the main, struct definitions and function prototypes. Could someone help me fix this code? Text Version: #include<stdio.h> #include<stdlib.h> #include <string.h> struct ip_address { int octet_1; int octet_2; int octet_3; int octet_4; }; typedef struct ip_address ip_address_t; void print_ip_address(ip_address_t ip1){ printf("%d.%d.%d.%d", ip1.octet_1,ip1.octet_2,ip1.octet_3,ip1.octet_4); } int is_valid(ip_address_t ip1){ if(ip1.octet_1 < 0...

  • I'm having trouble getting a certain output with my program Here's my output: Please input a...

    I'm having trouble getting a certain output with my program Here's my output: Please input a value in Roman numeral or EXIT or quit: MM MM = 2000 Please input a value in Roman numeral or EXIT or quit: mxvi Illegal Characters. Please input a value in Roman numeral or EXIT or quit: MXVI MXVI = 969 Please input a value in Roman numeral or EXIT or quit: EXIT Illegal Characters. Here's my desired output: Please input a value in...

  • Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers...

    Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers Sometimes we're given an array of data that we need to be able to view in sorted order while leaving the original order unchanged. In such cases we could sort the data set, but then we would lose the information contained in the original order. We need a better solution. One solution might be to create a duplicate of the data set, perhaps make...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT