commas.cpp) Write a program that accepts a 7-9) digit
//integer and echoes the number with commas between every
//three digits from the right. Test it with the numbers
//, 20300045, & 10000000
c++
// program inserts comas into number given
#include <iostream>
using namespace std;
int main()
{
int leadingDigits,middledigits,lastdigits;
int tempValue,original;
cout<< "please enter a 7-9 digit number.\n";
cin>>original;
tempValue=original/1000;
lastdigits=original%1000; // add code
lastdigits=original%100; // corrected code
leadingDigits=tempValue/1000;
middledigits=tempValue%1000; // add code
middledigits=tempValue%100; // corrected code
cout<<"the number with comas is "<<leadingDigits;
cout<< ","<<middledigits/1<< "," <<lastdigits/1<<endl; // correct this to print individual digits of middle and last digits
return 0;
}
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 3 images
- Finish the following code: void Divide (int dividend, int divisor, bool& error, float& result) // Set error to indicate if divisor is zero. // If no error, set result to dividend / divisor. { using namespace std; // For debugging cout << "Function Divide entered." << endl; cout << "Dividend = " << dividend << endl; cout << "Divisor = " << divisor << endl; //** // Rest of code goes here. //** // For debugging if (error) cout << "Error = true "; else cout << "Error = false "; cout << "and Result = " << result << endl; cout << "Function Divide terminated." << endl; }arrow_forwardLAB:Max of 2 Write a program that takes in two integers as inputs and outputs the largest value.arrow_forwardI need this code to be with python 3 1. Approach: Non recursive: //include necessary header files#include <iostream>using namespace std;//main functionint main(){ int days,buy_on_this_day ,sell_on_this_day; //get number of days as input from user cout<<"Enter number of days: "; cin>>days; int stock_price[days]; for(int i=0;i<days;i++) { cout<<"Enter stock_price"; cin>>stock_price[i]; } int i=0; for(int i=0;i<days-1;i++) { //comparing current price with next day price and finding the minima while(i<days-1 && stock_price[i+1]<=stock_price[i]) i++; if(i==days-1) break; buy_on_this_day =i++; while(i<days && stock_price[i]>= stock_price[i-1]) i++; sell_on_this_day =i-1; cout<<buy_on_this_day <<" : index of the change before we buy"<<endl; cout<<sell_on_this_day<<" :index…arrow_forward
- // LargeSmall.cpp - This program calculates the largest and smallest of three integer values. #include <iostream> using namespace std; int main() { // This is the work done in the housekeeping() function // Declare and initialize variables here int largest; // Largest of the three values int smallest; // Smallest of the three values // Prompt the user to enter 3 integer values // Write assignment, add conditional statements here as appropriate // This is the work done in the endOfJob() function // Output largest and smallest number. cout << "The largest value is " << largest << endl; cout << "The smallest value is " << smallest << endl; return 0; }arrow_forwardHelp plzarrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY