It is not detecting any syntax errors but it just ends instantly.

//********************************************
//File:wk1_change.cpp
//
//Summary: a program that whan given an amount of change will tell you what coins will be needed to equal that amount.
//
//author:
//Created Jan 2020

//*****************************************

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

void intro();
void input( int& amountLeft);
void computeCoins(int& amountLeft, int& qurt,int& dime, int& penny);
void output(int& qurt,int& dime, int& penny);

int main()
{ int amountLeft,
qurt,
dime,
penny;



void intro();
void imput(int& amountLeft);
void computeCoins(int& amountLeft, int& qurt,int& dime, int& penny);
void output( int& qurt,int& dime,int& penny);
return 0;
}

void intro()
{
cout<<"Please enter an amount of money from 1 to 99 cents and I will give the coins equal to that amount";
return;
}

void imput(int& amountLeft)
{
cin>>amountLeft;

while(amountLeft>99||amountLeft<1)
cout<<" Sorry please give a valid amount";
cin>>amountLeft;
return;
}

void computeCoins( int& amountLeft, int& qurt,int& dime, int& penny)
{ while(amountLeft<0)
{
while(amountLeft>=25)
{
amountLeft-25;
qurt++;
}

while(amountLeft>=10)
{
amountLeft-10;
dime++;
}

while(amountLeft>=1)
{
amountLeft-1;
penny++;
}
}
return;
}
void output(int& qurt,int& dime, int& penny)
{ cout<<"Change needed \n";
cout<< "Quarters:"<<qurt<<"\n Dimes:"<<dime<<"/n penny"<<penny;

return;
}










what does it do if you put
cin >> amountLeft;
before return 0 in main?

if that works, its working and just closing before you can see it. Fix by running from a command prompt or adding a cin statement at the end of all your programs.
@jonnin, so you've given up on telling people to use code tags?
At any rate, he's not calling the functions properly in main. Just re-declaring them.
Probably would show up better in code tags.
Look at this carefully and compare it to your original. It now runs but doesn't produce sensible output.

1. Next time use code tags pls.
2. You need to revise how function calls work.
3. You need to spell input consistently. It's not 'input' in one place and 'imput' in another.
4. I'm guessing but '-=' seems more appropriate than '-', but I haven't double checked - that's your project therefore your job.
5. 'when' isn't spelled 'whan'
6. Always initialise variables.
7. The idea, especially if it's your own, isn't too bad at all, so persevere with it because there isn't a lot to fix :)


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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//********************************************
//File:wk1_change.cpp
//
//Summary: a program that whan given an amount of change will tell you what coins will be needed to equal that amount.
//
//author:
//Created Jan 2020

//*****************************************

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

void intro();
void input( int& amountLeft);
void computeCoins(int& amountLeft, int& qurt,int& dime, int& penny);
void output(int& qurt,int& dime, int& penny);

int main()
{
    int amountLeft{0}, qurt{0}, dime{0}, penny{0};
    
    intro();
    input( amountLeft );
    computeCoins( amountLeft, qurt, dime, penny);
    output(qurt, dime, penny);
    
    return 0;
}

void intro()
{
    cout<<"Please enter an amount of money from 1 to 99 cents and I will give the coins equal to that amount";
    return;
}

void input(int& amountLeft)
{
    cin>>amountLeft;
    
    while(amountLeft>99||amountLeft<1)
    {
        cout<<" Sorry please give a valid amount";
        cin >> amountLeft;
    }
    return;
}

void computeCoins( int& amountLeft, int& qurt,int& dime, int& penny)
{
    while(amountLeft < 0)
    {
        while(amountLeft >= 25)
        {
            amountLeft -= 25;
            qurt++;
        }
        
        while(amountLeft >= 10)
        {
            amountLeft -= 10;
            dime++;
        }
        
        while(amountLeft >= 1)
        {
            amountLeft -= 1;
            penny++;
        }
    }
    return;
}

void output(int& qurt,int& dime, int& penny)
{
    cout<<"Change needed\n";
    cout<< "Quarters:" << qurt << "\n Dimes: " << dime << "/npenny " <<penny;
    
    return;
}
Last edited on
@jonnin, so you've given up on telling people to use code tags?

Well, I didn't look at the code because of tagsā€¦ but gave the default 'blink and gone' answer in case it was that.
Type:
System("pause")
or
cin.get()

This worked for me, so I hope it will work for you.

bpt
Topic archived. No new replies allowed.