-3
     cout << "Enter age: ";
     cin >> age;
    
     cout << "Enter the six digits of your first number (each seperated by a space): ";
     cin >> firOne >> firTwo >> firThree >> firFour >> firFive >> firSix;
    
     cout << "Enter the six digits of your second number (each seperated by a space): ";
     cin >> secOne >> secTwo >> secThree >> secFour >> secFive >> secSix;
    
    
     base = (2 * age) + 1;
    
     carrySix = (firOne + secOne) / (age + 1);
     carryFive = (firTwo + secTwo) / (age + 1);
     carryFour = (firThree + secThree) / (age + 1);
     carryThree = (firFour + secFour) / (age + 1);
     carryTwo = (firFive + secFive) / (age + 1);
     carryOne = (firSix + secSix) / (age + 1);
    
     sumOne = (firOne + secOne) - (carrySix * base) + carryFive;
     sumTwo = (firTwo + secTwo) - (carryFive * base) + carryFour;
     sumThree = (firThree + secThree) - (carryFour * base) + carryThree;
     sumFour = (firFour + secFour) - (carryThree * base) + carryTwo;
     sumFive = (firFive + secFive) - (carryTwo * base) + carryOne;
     sumSix = (firSix + secSix) - (carryOne * base);
    
     cout << sumOne << sumTwo << sumThree << sumFour << sumFive << sumSix;

I am trying to confirm my calculations, and once I cout<< the variables nothing is outputted. I am not sure why as the cout<< is working when I as a question like, "Enter age: ".

Thanks.

  • 1
    @user17171284 In future submissions, cut and paste the code into the question box, and then highlight it and press the "code" button. That way people don't have to leave the site to look at the code. It makes it easier on the people answering the questions, which means that more people will try to answer it. – Edwin Buck Oct 17 '21 at 01:07
  • 1
    Please do not use [`using namespace std;`](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice), as it is bad practice. – no ai please Oct 17 '21 at 01:19
  • @Someone_who_likes_SE Yes, I have heard this is not ideal to do, however, It is the way my assignment specs specify to do it. – user17171284 Oct 17 '21 at 01:25
  • @EdwinBuck Sorry about that, I have just added my code to the post – user17171284 Oct 17 '21 at 01:26
  • 1
    Your code is not complete. It cannot be copied and compiled as-is to reproduce your results. In particular, I would guess that the types of your variables is very significant here. You might want to run a test where you change `cout << sumOne << sumTwo << sumThree << sumFour << sumFive << sumSix;` to include some non-variable output, as in `cout << '|' << sumOne << sumTwo << sumThree << sumFour << sumFive << sumSix << '|';`. *Bonus:* Then do a bit more debugging to see if you can simplify the code demonstrating the issue. – JaMiT Oct 17 '21 at 01:37

2 Answers2

1

Did you try

cout << "Some message" << std::flush;

flushing a stream will make sure that input isn't held in a display buffer.

Display buffers typically hold the characters until there are "enough" or some special sequence (like std::endl) is sent. By calling the flush manually, you can force the display buffers to clear, putting the output into the terminal.

Edwin Buck
  • 69,361
  • 7
  • 100
  • 138
  • 2
    A newline doesn't flush the stream. That's the main difference between `'\n'` and `std::endl`. – Thomas Sablik Oct 17 '21 at 00:59
  • @ThomasSablik Thanks for the note, I'll update the answer. Personally, I've never used an escaped newline, as I was told early to always use `std::endl` instead. – Edwin Buck Oct 17 '21 at 01:01
  • @ThomasSablik I was under the impression that `std::endl` was a bit more portable, should it ever be ported to a Windows platform. Still, it's nice to know that I'll kill performance by using it. I'll use it sparingly, but really, any kind of console output is a bit slow. – Edwin Buck Oct 17 '21 at 01:05
  • 2
    I recommend to always use `'\n'` instead of `std::endl`. `'\n'` is portable. It will also work on Windows and MacOS. – Thomas Sablik Oct 17 '21 at 01:06
  • `cout` flushes as part of its destructor, which is run at the end of the program unless the program ends abnormally. (It's a little more involved than that, but close enough.) – chris Oct 17 '21 at 01:07
  • I just tried, did not work unfortunately. Thanks for the help though. – user17171284 Oct 17 '21 at 01:40
1

You have typo, sumSi should be sumSix

AssGoblin69
  • 802
  • 3
  • 11
  • Sorry I have just posted the code here, that was a something I fixed a while ago, regardless it should not affect the whole output. – user17171284 Oct 17 '21 at 01:22