Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

JASdeep11

  • 2 years ago

Need help finishing this code its supposed to print out commas after every third # but it is adding an extra 0 at the end of both commas

  • This Question is Closed
  1. JASdeep11
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    #include<iostream> using namespace std; int main() { int first3, middle3, last3; int original, temp, first, second,third, fourth, first1, second1, third1, fourth1; cout<<"enter a 7-9 digit number"<<endl; cin>>original; temp=original/1000; last3=original%1000; first=last3/10; second=last3%10; third=first/10; fourth=first%10; first3=temp/1000; middle3=temp%1000; first1=middle3/10; second1=middle3%10; third1=first1/10; fourth1=first1%10; cout<<"the number with a comma is "<<endl; cout<<first3<<","<<first1<<second1<<third1<<","<<first<<second<<third<<endl; return 0; }

  2. JASdeep11
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    i doesnt put zeros it just puts some random numbers

  3. eSpeX
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    http://ideone.com/RhtIN input: 123456789 output: enter a 7-9 digit number temp= 123456 last3= 789 first= 78 second= 9 third= 7 fourth= 8 first3= 123 middle3= 456 first1= 45 second1= 6 third1= 4 fourth1= 5 the number with a comma is 123,4564,7897 It is just a matter of keeping track of your variables.

  4. JASdeep11
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    @eSpeX So what would i type in the last cout statement to get it write

  5. eSpeX
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    cout<<first3<< ","<<middle3<<","<< last3<< endl; I added this line to your code and below is the output with your code and the new code as the last two lines. input: 1234567 output: enter a 7-9 digit number temp= 1234 last3= 567 first= 56 second= 7 third= 5 fourth= 6 first3= 1 middle3= 234 first1= 23 second1= 4 third1= 2 fourth1= 3 the number with a comma is 1,2342,5675 1,234,567 http://ideone.com/8KhZZ

  6. rsmith6559
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    A pretty printed number is a string. it's easier to do the fomatting with the string than th number.

  7. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Ask a Question
Find more explanations on OpenStudy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.