Jump to content

C++ problems

Xanter2002

Hello everyone, I am a starter in C++ and as homework I have to calculate a*b=c and a-b=d, but I have a problem about the b.

Let's say that I have these numbers: 12 and 3.

The a is read correctly, but b isn't

this is the code:  

#include <iostream>
     using namespace std;
     int main ()
     {
         int a,b,c,d;
         cin>>a,b;
         c=a*b;
         d=a-b;
         cout<<c<<" "<<d;
     }

I cannot see any difference between this and the others that I have as homework and the ones that I made in class.

Could you help me?

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, M.Yurizaki said:

Can you elaborate for the record? :3

It means to write what was the problem?

 

Link to comment
Share on other sites

Link to post
Share on other sites

good on you for figuring it out, but I would point out that it's a bad habit to treat the = in programming like the = in math.

 

19 minutes ago, Xanter2002 said:

a*b=c and a-b=d

doesn't make sense in programming, since you can't set the multiplication of two values to a different value. Think of = in programming as a "set to" operation, and unless you are making up your own vector space axioms you are probably not going to be trying to set what the product of 2 numbers should be, as opposed to setting some value to the product of 2 numbers.

 

The reason it kind of matters, is because a*b=c could actually be something in programming (well, close it's missing some syntax). You could be assigning the memory address found at a*b to the value of c, but since you're not talking about that in this case, you don't want to confuse anyone.

Gaming build:

CPU: i7-7700k (5.0ghz, 1.312v)

GPU(s): Asus Strix 1080ti OC (~2063mhz)

Memory: 32GB (4x8) DDR4 G.Skill TridentZ RGB 3000mhz

Motherboard: Asus Prime z270-AR

PSU: Seasonic Prime Titanium 850W

Cooler: Custom water loop (420mm rad + 360mm rad)

Case: Be quiet! Dark base pro 900 (silver)
Primary storage: Samsung 960 evo m.2 SSD (500gb)

Secondary storage: Samsung 850 evo SSD (250gb)

 

Server build:

OS: Ubuntu server 16.04 LTS (though will probably upgrade to 17.04 for better ryzen support)

CPU: Ryzen R7 1700x

Memory: Ballistix Sport LT 16GB

Motherboard: Asrock B350 m4 pro

PSU: Corsair CX550M

Cooler: Cooler master hyper 212 evo

Storage: 2TB WD Red x1, 128gb OCZ SSD for OS

Case: HAF 932 adv

 

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, reniat said:

good on you for figuring it out, but I would point out that it's a bad habit to treat the = in programming like the = in math.

 

doesn't make sense in programming, since you can't set the multiplication of two values to a different value. Think of = in programming as a "set to" operation, and unless you are making up your own vector space axioms you are probably not going to be trying to set what the product of 2 numbers should be, as opposed to setting some value to the product of 2 numbers.

I know, but there I wrote in short the exercice that I had, but if you look in the program, you can see that I wrote correctly. :)

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×