Click here to Skip to main content
15,392,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So instead of printing the texts, the result I got was always only the first cout I inserted (2). I've only just started coding and I'm still grasping the basics. What do I do?

What I have tried:

#include <iostream>
using namespace std;

int main ()
{
int x;
int y; 
int sum;
int product;
int difference;
int quotient; 
cout << "2"; 
cin >> x; 
cout << "3"; 
cin >> y; 
sum = x + y; 
product = x*y;
quotient = x/y;
difference = x - y;
cout << "Sum is: " << sum<<endl; 
cout << "Product is: " << product<<endl;
cout << "Quotient is: " << quotient<<endl;
cout << "Difference is: " << difference<<endl;
return 0;

}
Posted
Updated 24-Oct-21 23:45pm
v3
Comments
Rick York 25-Oct-21 11:56am
   
If your program is waiting for input then it is usually best to output a message saying so. In your case, it should write, "Enter x value : " or something similar when it is waiting for x to be entered and something like that when it is waiting for y to be entered.

It works fine when I try it.
1. It prints 2 and waits for an input number (x).
2. It prints 3 and waits for an input number (y).
3. It calculates the sum, product, quotient and difference of x and y.
4. It prints those values as shown below on my output:
24
35
Sum is: 9
Product is: 20
Quotient is: 0
Difference is: -1


What exactly do you think is wrong with the answers?
   
Comments
JJhis ae 25-Oct-21 6:05am
   
It only prints "2" on my pc for some reason but thank you for pointing out that the problem is only from my end
Richard MacCutchan 25-Oct-21 6:20am
   
That is correct, and at that point it is waiting for you to enter your choice of value for x. Similarly when it prints 3, you need to enter the value for y.
If it prints "2" and does nothing at all after that, it's probably waiting for you to enter a number and press the ENTER key ...
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900