#How do I update integers?

32 messages · Page 1 of 1 (latest)

golden tigerBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

halcyon adder
#

!code

golden tigerBOT
#
How to Format Code on Discord
Markup

```cpp
int main() {}
```

Result
int main() {}
faint summit
#

!f

golden tigerBOT
#
#include <Windows.h>
#include <cstdlib>
#include <iostream>
#include <string>

using namespace ::std;

int main() {
  system("CLS");

  int balance = 60;

  wcout << "car 1  =  $90" << endl << "car 2  =  $20" << endl;
  string mainMenu;
  while (mainMenu != "q") {
    getline(cin, mainMenu);

    if (mainMenu == "car 1") {
      if (balance < 90) {
        wcout << "you can't afford this car" << endl;
      } else if (balance > 90) {
        wcout << "you have purchased car 1!" << endl
              << "new balance: " << balance - 90 << endl;
      } else {
        wcout << "you have purchased car 1!" << endl
              << "new balance: " << balance - 90 << endl;
      }
    }

    else if (mainMenu == "car 2") {
      if (balance < 20) {
        wcout << "you can't afford this car" << endl;
      } else if (balance > 20) {
        wcout << "you have purchased car 2!" << endl
              << "new balance: " << balance - 20 << endl;
      } else {
        wcout << "you have purchased car 2!" << endl
              << "new balance: " << balance - 20 << endl;
      }
    }
  }
}
jake
tidal scarab
#

dont include windows.h and don't use system please

near ore
#

It is supposed to update the balance after every purchase, it only updates the original balance

halcyon adder
#

You update them using =.

balance = balance - 20;
std::cout << "your new balance is " << balance << '\n';

The first line can be shortened to balance -= 20;

tidal scarab
#

instead of balance - 90 do balance -= 90

#

balance -= 90 subtracts 90 from the balance and returns the value

tidal scarab
#

;compile -includeiostream

int balance = 100;
std::cout << (balance -= 90);
subtle pantherBOT
#
Program Output
10
halcyon adder
#

Doing std::cout << "your new balance is " << (balance -= 20) << '\n'; works too, as nevemlaci said, but it's kinda cursed

tidal scarab
#

you can tag me lol im here c:

halcyon adder
#

Didn't want to 😛

faint summit
#

@tidal scarab

halcyon adder
#

@tidal scarab

strong dew
#

@ nevemlaci

golden tigerBOT
#

@near ore

Please Do Not Delete Posts!

Please don't delete forum posts. They can be helpful to refer to later and other members can learn from them. In the future you can use !solved to close a post and mark a post as solved.

near ore
#

!solved

golden tigerBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity

faint summit
halcyon adder
#

----------------------balance?

faint summit
strong dew
#

Is there a safer way to do what system("CLS") does

faint summit