Hello. I'm new here. I'm learning in Dev-C++ and so far i made a simple console. It's about sorting small and big coins.
Now i finish the code, and i wanna to improve it. Was searching for answer and come close to what i need, but i face
with a problem when i try to merge the 2 codes that i wrote.
The first code is to sort how many small or big coins are inserted in the deposit.
The second code is a program that will only tell me when i have put more than 4 coins and so on...(4, 5, 6...)
- Small coins: 1, 3, 5.
- Big coins: 10, 20, 30.
Example for the first code:
- I enter the following numbers:
1-1-5-3-3-5-20-1-30-10-20-10-10-30
Now the first code is for the value of coins and it runs like this:
Please Enter The Value Of Coins: 1
Small Coins Counted: 1
Please Enter The Value Of Coins: 1
Small Coins Counted: 2
Please Enter The Value Of Coins: 5
Small Coins Counted: 3
Please Enter The Value Of Coins: 3
Small Coins Counted: 4
Please Enter The Value Of Coins: 3
Small Coins Counted: 5
Please Enter The Value Of Coins: 5
Small Coins Counted: 6
Please Enter The Value Of Coins: 20
Big Coins Counted: 1
Please Enter The Value Of Coins: 1
Small Coins Counted: 1
Please Enter The Value Of Coins: 30
Big Coins Counted: 1
Please Enter The Value Of Coins: 10
Big Coins Counted: 2
Please Enter The Value Of Coins: 20
Big Coins Counted: 3
Please Enter The Value Of Coins: 10
Big Coins Counted: 4
Please Enter The Value Of Coins: 10
Big Coins Counted: 5
Please Enter The Value Of Coins: 30
Big Coins Counted: 6
Example for the second code:
- I enter the following amount of coins:
2-1-1-2-1-3
The second code is to count how many coins i insert
and it will print after i insert 4 or more amount of coins:
Number Of Insert Coins: 2
Insert Next Number of inserted coins: 1
Insert Next Number of inserted coins: 1 (<- this is where i reach 4 coins)
Total Number of coins inserted is: 4
Type The Next Number Of Coins Inserted : 1
Total Number of coins inserted is: 5
Type The Next Number Of Coins Inserted : 1
Total Number of coins inserted is: 6
Type The Next Number Of Coins Inserted : 2
Total Number of coins inserted is: 8
Type The Next Number Of Coins Inserted : 1
Total Number of coins inserted is: 9
Type The Next Number Of Coins Inserted : 3
Total Number of coins inserted is: 12
Now this is my problem trying to merge this 2 codes together and make the output look like this:
Using the same numbers:
1-1-5-3-3-5-20-1-30-10-20-10-10-30
Console output:
Please Enter The Value Of Coins: 1
Please Enter The Value Of Coins: 1
Please Enter The Value Of Coins: 5
Please Enter The Value Of Coins: 3
Small Coins Counted: 4
Please Enter The Value Of Coins: 3
Small Coins Counted: 5
Please Enter The Value Of Coins: 5
Small Coins Counted: 6
Please Enter The Value Of Coins: 20
Please Enter The Value Of Coins: 1
Please Enter The Value Of Coins: 30
Please Enter The Value Of Coins: 10
Please Enter The Value Of Coins: 20
Please Enter The Value Of Coins: 10
Big Coins Counted: 4
Please Enter The Value Of Coins: 10
Big Coins Counted: 5
Please Enter The Value Of Coins: 30
Big Coins Counted: 6
Can some one help me to merge this 2 codes together?
Thank you very much, and i appreciate your attention.
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
|
//This is the first code
#include <iostream>
using namespace std;
int main(int argc, char argv)
{
bool misss1b2 = false;
int s1b2 = 0;
for(;;)
{
int a;
cout << endl << "Please Enter The Value Of Coins: ";
cin >> a;
if(a == 1 || a == 3 || a == 5 )
{
if(misss1b2 == false)
{
s1b2=1;
misss1b2 = true;
}
else
{
s1b2++;
}
cout << endl << "Small Coins Counted: " << s1b2 << endl;
}
else
{
if(a == 10 || a == 20 || a == 30)
{
if(misss1b2 == true)
{
misss1b2 = false;
s1b2 = 1;
}
else
s1b2 ++;
cout << endl << "Big Coins Counted: " << s1b2 << endl;
}
}
}
return 0;
}
|
// This is the second code
#include <iostream>
using namespace std;
int main()
{
int coins = 1;
int coins2 = 3;
int a;
int b = 1;
int c;
cout << " Number Of Insert Coins: " ;
for (;;)
{
if (coins < 4)
{
while(coins < 4)
{
cin >> a;
cout << " Insert Next Number of inserted coins: ";
coins = coins + a;
b = b + 1;
}
}
else (coins2 > 4 || coins2 == 4);
{
//If the number of coins inserted is greater than 10 than the program will print how much coins where inserted in the safebank
cin >> a;
coins2 = coins2 + a;
cout << endl << "Total Number of coins inserted is: " << coins2 << endl;
cout << endl << " Type The Next Number Of Coins Inserted : ";
}
}
return 0;
} |