USING C++ PROGRAM Write a program to compute, and output to the screen, the numb
ID: 3838003 • Letter: U
Question
USING C++ PROGRAM
Write a program to compute, and output to the screen, the number of cat treats that can be bought from a vending machine, along with amount of resulting change. Each treat costs 47¢ and purchases are made in whole-dollar increments, such as $1, $2, $3, $4, $5, ellipsis, that are input, via the keyboard, by the user. For example, if a person inserts $4, they will recieve 8 treats and 24¢ change. Your submission should include a screenshot of the execution of the program using each of the values $1, $7 and $29. Write a program to compute, and output to the screen, the value of the variable x of the polynomial x^2 + 2x = 1 = p, for some constant P greaterthanorequalto 0 that is input, via the keyboard, by the user. For example. If p = 9, then x = 2. Your submission should include a screenshot of the execution of the program using each of the values p = 0.14, 16, 151.93.Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
int money;
cout<<" W-E-L-C-O-M-E VENDING MACINE ";
cout<<" Each treat cost is 47 cent ";
cout << "Insert a Money : $";
cin>>money;
int treat,change;
treat=(money*100)/47;
change=(money*100)%47;
cout<<"You receive "<<treat <<" treats and change "<<change<<" cents ";
return 0;
}
------------------
output sample 1:-
W-E-L-C-O-M-E VENDING MACINE
Each treat cost is 47 cent
Insert a Money : $4
You receive 8 treats and change 24 cents
-----------------
output sample 2:-
W-E-L-C-O-M-E VENDING MACINE
Each treat cost is 47 cent
Insert a Money : $1
You receive 2 treats and change 6 cents
-----------
output sample 3:-
W-E-L-C-O-M-E VENDING MACINE
Each treat cost is 47 cent
Insert a Money : $7
You receive 14 treats and change 42 cents
----------------------
output sample 4:-
W-E-L-C-O-M-E VENDING MACINE
Each treat cost is 47 cent
Insert a Money : $29
You receive 61 treats and change 33 cents
------------------------------------------------------------------------------------------------------------------------------
Answer 2:-
#include <iostream>
#include <cmath>
using namespace std;
int main() {
float a,b,p, c, x1, x2, determinant;
cout << "Enter the value of P : ";
cin >>p;
a=1;
b=2;
c=(1-p);
determinant = b*b - 4*a*c;
x1 = (-b + sqrt(determinant)) / (2*a);
cout << "x = " << x1 << endl;
return 0;
}
-------------
output sample 1:-
Enter the value of P : 9
x = 2
----------
output sample 2:-
Enter the value of P : 0.14
x = -0.625834
---------------------------------
Enter the value of P : 16
x = 3
--------------
Enter the value of P : 151.93
x = 11.326
---------------------------------------------------------------------------------------------
If you have any query, please feel free to ask.
Thanks a lot.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.