Trouble reinitializing values with subprograms
Dec 7, 2014 at 11:06pm UTC
Hi, I'm trying to make a cash register program, but first I need to reinitialize ones, fives, tens, and twenties to their correct dollar amount. However, whenever I try to pass the user inputted values to the function that calculates the correct dollar amount, it just prints the same number.
Can anyone please help me?
Here's my code:
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#include <iostream>
#include <string>
using namespace std;
//dollarAMT - recalculates the actual dollar amount
void dollarAMT(int ones, int fives, int tens, int twenties){
int newOne = ones;
int newFives = fives * 5;
int newTens = tens * 10;
int newTwenties = twenties * 20;
//reinitialize dollar amount
ones = newOne;
fives = newFives;
tens = newTens;
twenties = newTwenties;
}
int main() {
string command;
int till;
int ones;
int fives;
int tens;
int twenties;
cout << "Enter cash: ones fives tens twenties" << endl;
cin >> ones >> fives >> tens >> twenties;
dollarAMT(ones, fives, tens, twenties);
cout << ones << " " << fives << " " << tens << " " << twenties << endl;
return 0;
}
Dec 7, 2014 at 11:12pm UTC
Use by reference function parameters.
Dec 7, 2014 at 11:14pm UTC
Ooooooh,
It's working now thanks :)
Topic archived. No new replies allowed.