Program needed to display a message

I need help to write a code in C++ in visual studio 2015 for displaying the following message.The program should ask the user to enter the amount in euros(double) paid in a restaurant and separate the euros and cents,convert them to integers and display them,lie shown below:

Enter the bill in Euro: 35.76
This is 35 euros and 76 cents
You need to try to write it yourself. If you get stuck for more than 30 minutes then come back, post your code and your question.

Coding is like playing football. The only way to learn to do it is to practice. You can't become a good football player by asking someone else to practice for you.
#include <iostream>
using namespace std;
int main()
{
int n, result = 0;


the above is the only thing i could do myself,please help me furthur :)
I'll tell you what, read the tutorials and write a version of the program that prompts for the bill and then prints it out:
Enter the bill in Euro: 35.76
This is 35.76.

Note that you will want to store the amount in a double, not an integer for this part.

Once you have that working, you can extract the euros and cents. To get the euros, just assign the (double) bill amount to an integer variable. C++ truncates the double when you do this:
1
2
3
double bill;
...
int euros = bill;


To get the cents, start by multiplying the bill by 100 to get the total number of cents. Then extract the cents with the modulo (%) operator:
int cents = (bill*100) % 100;
The modulo takes the remainder. so a%b is the remainder of a / b.
do you know how will i print the code in my source file of c++ program in visual studio 2015?
Here is an image tutorial: http://i.imgur.com/mTGphaE.jpg
how will i print the code in another computer which doesn't has visual studio 2015 installed?
Can anyone reduce the below codes to a much shorter one:-

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
#include <iostream>
using namespace std;
int main() {

		int euros, num;
		cout << "Enter total amount in Euros: ";
		cin >> euros;
		num = euros / 500;
		cout << "Pay: " << num << " five-hundred notes\n";
		euros = euros % 500;
		num = euros / 200;
		cout << "Pay: " << num << " two-hundred notes\n";
		euros = euros % 200;
		num = euros / 100;
		cout << "Pay: " << num << " one-hundred notes\n";
		euros = euros % 100;
		num = euros / 50;
		cout << "Pay: " << num << " fifty notes\n";
		euros = euros % 50;
		num = euros / 20;
		cout << "Pay: " << num << " twenty notes\n";
		euros = euros % 20;
		num = euros / 10;
		cout << "Pay: " << num << " ten notes\n";
		euros = euros % 10;
		num = euros / 5;
		cout << "Pay: " << num << " five notes\n";
		euros = euros % 5;
		num = euros / 2;
		cout << "Pay: " << num << " two coins\n";
		euros = euros % 2;
		num = euros;
		cout << "Pay: " << num << " one coins\n";
		
	system("pause");
	return 0;
} 


This is for a program to display the following message:-

Enter total amount in Euros: 2194
Pay: 4 five-hundred notes
0 two-hundred notes
1 one-hundred notes
1 fifty notes
2 twenty notes
0 ten notes
0 five notes
2 two coins
0 one coins
Last edited on
You can shorten it by using a function.

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
#include <iostream>
#include <string>
using namespace std;

void Disburse (int & euros, int val, const string & descr)
{   int num;
    num = euros / val;
    cout << "Pay: " << num << " " << descr << endl;
    euros -= num * val;
}
            
int main() 
{   int euros;
    cout << "Enter total amount in Euros: ";
    cin >> euros;
    Disburse (euros, 500, "five-hundred notes");
    Disburse (euros, 200, "two-hundred notes");
    Disburse (euros, 100, "one-hundred notes");
    Disburse (euros, 50,  "fifty notes");
    Disburse (euros, 20,  "twenty notes");
    Disburse (euros, 10,  "ten notesn");
    Disburse (euros, 5,   "five notes");
    Disburse (euros, 2,   "two coins");
    Disburse (euros, 1,   "one coins");
    system("pause");
    return 0;
} 


PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
How to put a new line after the result in the following code?

<#include <iostream>
using namespace std;


int main()
{
int grade;

cout << "Enter your grade: ";
cin >> grade;

if (grade > 100 || grade < 0)
cout << "Not a valid grade";
else {
cout << "You got ";
if (grade >= 90)cout << "an A";
else if (grade >= 80) cout << "a B";
else if (grade >= 70) cout << "a C";
else if (grade >= 60) cout << "a D";
else cout << "an F";
}
system("pause") ;

return 0;
}>
Last edited on
Before system("pause"); add cout << '\n';
Topic archived. No new replies allowed.