A
A
Artem Marenkov2020-06-26 09:44:55
C++ / C#
Artem Marenkov, 2020-06-26 09:44:55

How can I write this code so that it returns 00 and not 0?

Hello! I'm having a problem with an outgoing value in C++.
More: I am taking a course on Stepik on solving problems in C ++ and met the following task there: https://stepik.org/lesson/54364/step/3?auth=regist...
Everything is clear with the first output, but not with the second very. How can I make it output 12 and 00 instead of 12 and 0? Am I stupid or the creators of the course screwed up?
Thanks in advance)

#include <iostream>
using namespace std;
int main() {
    int num = 0;
    
    cin >> num;
    
    int number1 = num/100;
    int number2 = num%100;
    
    cout << number1 << " " << number2 << endl;
  return 0;
}

If someone does not open the link:
5ef59a1e874e7737515887.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2020-06-26
@Mart14

cout << setfill('0') << setw(2) << number1 << ' ' << setw(2) << number2;

V
vanyamba-electronics, 2020-06-26
@vanyamba-electronics

cout << number1 << ‘ ‘;
If (number2 < 10)
  cout << ‘0’;
cout << number2;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question