Help with a C++ program

I am stuck on my program. If anyone can help me it would be extremely appreciated. I have been trying to go this program for days and have had little to no succes with it. I don't know what to do for some reason when i enter 1 into it it does not show up in the slot?


Heres the 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
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
84
85
86
87
88
89
90
91
92
93
94
95
#include<iostream>
#include <conio.h>
#include <iomanip> //use for setw
using namespace std;

int main()
{
    int intnum, quarters, dimes, nickels;
    double decnum, money, slot=0.00, coinreturn=0.00;
    bool flag=true;
    
    
    do
    {
         // setprecision(2) so that the 0.00 will appear in the executable.
      cout << setprecision(2) << fixed;      
      slot=0.00;
      coinreturn=0.00;
      
      do
      {
                system("cls");
         cout<<endl;
         cout << setw(35) << "ICE COLD COLA";
         cout << endl;
         cout << setw(33) << ".75 cents";
         cout << endl;
         cout << endl;
         cout <<"         Deposit -- dollar, quarters, dimes, or nickels:";
         cout << endl;
         cout << setw(22) << "( 1" << "    ," << setw(6)<< " .25" << "   ,"   
              <<  "  .10" << " ," << setw(8) << " .05" << " )";
         cout << endl;
         cout << endl;
         cout << setw(16) << "Slot"<<" [" << slot <<" ]" <<" :";
         cout << endl;
         cout << endl;
         cout << endl;
         cout << endl;
         cout << setw(14) << "Coin Return" <<" [" << coinreturn <<" ]" <<" :";
         cout << endl;
         cout << endl;
         cout << setw(10) << "     Enter Coin" << "[" << "------" <<"]" << " ";
        cin>> money;
        cout<<endl<<endl;
        
        /* makes it so that when .05, .10, .25, and $1.00 is entered into the 
           machine the money will be added together and shown in the slot     
           Any amount of money that is not equal to .05, .10, .25, and $1.00
           will be placed in the coin return.
        */
        
        if (money == 1.00 || money == 0.25 || money == 0.10 || money == 0.05)
            slot += money; 
        else
            coinreturn += money;
      
        
        
      }while(slot <= .75 && money != -1);
      
       cout<<"   Here is your Cola!"<<endl<<endl<<endl;
       cout<<"   Have a nice day!"<<endl;
      
      decnum = (slot - .75);
      
       //use static_cast to convert a double into an integer
       
       intnum = static_cast<int>((decnum +.005) * 100);
    
      
       quarters = intnum/25;
       intnum = intnum%25;
    
       dimes = intnum/10;
       intnum = intnum%10;
    
       nickels = intnum/5;
       intnum = intnum%5;
       
    
       cout<< endl<< endl<< "  Your change is: " <<endl;
       cout<<"\t"<< quarters <<" Quarter(s)"<<endl;
       cout<<"\t"<< dimes <<" Dime(s)"<<endl;
       cout<<"\t"<< nickels<< " Nickel(s)"<<endl;
       
                  
      system("pause");

      
    }while(money != -1);   
    
    cout<<endl<<endl<<endl;
    
}

Last edited on
Warnings do not prevent compilation.
Also, when there's a warning or error message, you need to post the exact wording and the corresponding line number.
And http://www.cplusplus.com/articles/z13hAqkS/
Alright I have edited my former post with my new code, and I am still not getting the results I need.
@bwilson
So, basically you want your code to show the total amount in the slot and the coin return. Am I correct? If that is indeed the case, then I've rewritten your codes with slight modifications. Have a look at it.

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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <cstdlib>
#include<iostream>
#include <conio.h>
#include <iomanip> //use for setw
using namespace std;
double slot=0.00,coinreturn=0.00;   //MADE GLOBAL

void Update()                       //PLACED IN A DIFFERENT SUBROUTINE
{
system("cls");

         cout<<endl;
         cout << setw(35) << "ICE COLD COLA";
         cout << endl;
         cout << setw(33) << ".75 cents";
         cout << endl;
         cout << endl;
         cout <<"         Deposit -- dollar, quarters, dimes, or nickels:";
         cout << endl;
         cout << setw(22) << "( 1" << "    ," << setw(6)<< " .25" << "   ,"
              <<  "  .10" << " ," << setw(8) << " .05" << " )";
         cout << endl;
         cout << endl;
         cout << setw(16) << "Slot"<<" [" << slot <<" ]" <<" :";
         cout << endl;
         cout << endl;
         cout << endl;
         cout << endl;
         cout << setw(14) << "Coin Return" <<" [" << coinreturn <<" ]" <<" :";
         cout << endl;
         cout << endl;
         cout << setw(10) << "     Enter Coin" << "[" << "------" <<"]" << " ";
}
int main()
{
    int intnum, quarters, dimes, nickels;
    double decnum, money;
    bool flag=true;


    do
    {
         // setprecision(2) so that the 0.00 will appear in the executable.
      cout << setprecision(2) << fixed;
      slot=0.00;
      coinreturn=0.00;

      do
      {
        Update();
        cin>> money;
        cout<<endl<<endl;

        /* makes it so that when .05, .10, .25, and $1.00 is entered into the
           machine the money will be added together and shown in the slot
           Any amount of money that is not equal to .05, .10, .25, and $1.00
           will be placed in the coin return.
        */

        if (money == 1.00 || money == 0.25 || money == 0.10 || money == 0.05)
            slot += money;
        else
            coinreturn += money;



      }while(slot < .75 && money != -1);    //CHANGED FROM slot<=.75

        Update();
        cout<<endl<<endl;

       cout<<"   Here is your Cola!"<<endl<<endl<<endl;
       cout<<"   Have a nice day!"<<endl;

      decnum = (slot - .75);

       //use static_cast to convert a double into an integer

       intnum = static_cast<int>((decnum +.005) * 100);


       quarters = intnum/25;
       intnum = intnum%25;

       dimes = intnum/10;
       intnum = intnum%10;

       nickels = intnum/5;
       intnum = intnum%5;


       cout<< endl<< endl<< "  Your change is: " <<endl;
       cout<<"\t"<< quarters <<" Quarter(s)"<<endl;
       cout<<"\t"<< dimes <<" Dime(s)"<<endl;
       cout<<"\t"<< nickels<< " Nickel(s)"<<endl;


      system("pause");


    }while(money != -1);

    cout<<endl<<endl<<endl;

}

@Pravesh Koirala

You are a wonderful, amazing, grade saving hero. Thanks so much for your help you assumed correct I wanted my code to show the total amount in the slot and the coin return.
Last edited on
:D, It's always nice to be appreciated
Topic archived. No new replies allowed.