You are viewing our Forum Archives. To view or take place in current topics click here.
need help with a simple code (C++)
Posted:

need help with a simple code (C++)Posted:

TTG-HyPer
  • TTG Master
Status: Offline
Joined: Jun 12, 201113Year Member
Posts: 843
Reputation Power: 36
Status: Offline
Joined: Jun 12, 201113Year Member
Posts: 843
Reputation Power: 36
I've just started learning C++ about half an hour ago and i'm try to make a simple think of a number code but i don't know the command to say that the input number equals A after dividing it by 2 and then A+4=B and then it prints the value of B.

Sorry if it is confusing you i do not know the proper terms, here is the code

#include <iostream>

using namespace std;

int main()
{
    int answer, a, b;

    cout<< "pick a number, times it by two then add 4";
    cout<< "Enter your answer here: ";
    cin>> answer;
    cin.ignore();
    answer/2=a;   //this is where i am stuck, i don't know what to put before this line
    a-4=b;        //and before this line
    cout<< "the number you was thinking of is: " << b << "";
}


please could you tell me the correct command for this and possibly define the command so i can use it later on?
#2. Posted:
speed
  • Summer 2020
Status: Offline
Joined: Jun 11, 200915Year Member
Posts: 9,897
Reputation Power: 3160
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Status: Offline
Joined: Jun 11, 200915Year Member
Posts: 9,897
Reputation Power: 3160
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
I'm not big on c++, but try this. This is the way most languages work, don't see any reason it would be different in c++:

   
a = answer/2; //this is where i am stuck, i don't know what to put before this line
b = a-4;    //and before this line
#3. Posted:
TTG-HyPer
  • TTG Master
Status: Offline
Joined: Jun 12, 201113Year Member
Posts: 843
Reputation Power: 36
Status: Offline
Joined: Jun 12, 201113Year Member
Posts: 843
Reputation Power: 36
SPEED wrote I'm not big on c++, but try this. This is the way most languages work, don't see any reason it would be different in c++:

   
a = answer/2; //this is where i am stuck, i don't know what to put before this line
b = a-4;    //and before this line


thank you it worked! i feel stupid not knowing that, it's so simple
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.