4.16 Lab 2 Part 3 Students, This content is controlled by your instructor and is
ID: 3791761 • Letter: 4
Question
4.16 Lab 2 Part 3 Students, This content is controlled by your instructor and is not zyBook content Diect questions or concerns about this content to your instructor. If you have any technical issues with the submission system, use the Trouble with button at the bottom. Use Branching to solve the following problem: You are trying to get enough change to make a dollar. You want to write a program that counts the amount of change you have and tels you how far you are away from a dollar. Example: (Based on inputs of: 2,2,2,1) Input how many pennies, nickels, dimes, and quarters do you have? Pennies: 2 Nickels: 2 Dimes: 2 Quarters: 1 You are 0.65 cents short of a dollar Your output should match exactly based on any input value. Submission 4.16.1: Lab 2 Part 3 main.cpp Load default template 1 sinclude kiostreamy 2 using namespace sta;Explanation / Answer
//CPP Program
#include <iostream>
using std::cout; // program uses cout
using std::cin; // proram uses cin
using std::endl; // program uses endl
int main() // function main begins program execution
{
int p,n,d,q; // creates integer for money input
const double PENNY = 0.01; // creates constant integer for penny
const double DIME = 0.10; // creates constant integer for dime
const double QUARTER = 0.25; // creates constant integer for quarter
const double NICKEL = 0.05; // creates constant integer for nickel
double doller=1.0;
double total = 0.0; //answer for amount is money * 100 / choice
cout << "Please enter how many pennis,nickels,dines,quaretes you have ?"<<endl; //prompts user
cin >> p>>n>>d>>q; // user enters dollar amount
total= (p*PENNY+n*NICKEL+d*DIME+q*QUARTER);
int shorts =int(total*100)%100;
int remshorts=100-shorts;
cout << "You are :" << remshorts <<" cents short of dollar" <<endl;
system("pause"); // keep window open
return 0; // indicates successful termination
}
Output :
Please enter how many pennis,nickels,dines,quaretes you have ?
101
20
10
4
You are :99 cents short of dollar
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.