Reputation: 39
I am making it so it adds, multiples, subtracts, and divides. I am running it through my command prompt and I dont know how to make it so there is a space between each calculation. Or Even if I can get them on separate lines. But just a space would be fine.
#include <iostream> //io from console
int main() //app entry point
{
int num1; //first variabe
int num2; //second variable
int sum; //sum of 2 variabes
int product; //product of 2 variabes
int difference; //differencr of 2 variabes
int quotient; //quotient of 2 variabe
std::cout << "Enter first number: "; //prompt user for input
std::cin >> num1; //assigns input to num1
std::cout << "Enter second number "; //prompt user for input
std::cin >> num2; //assigns inout to num2
sum = num1 + num2; //calcs the sum
std::cout << "The sum is " << sum; //displays the sum
product = num1 * num2; //calcs the product
std::cout << " The product is " << product; //displays the product
difference = num1 - num2; //calcs the product
std::cout << " The difference is " << difference; //displays the difference
quotient = num1 / num2; //calcs the quotient
std::cout << " The quotient is " << quotient; //displays the quotient
}
Upvotes: 1
Views: 202
Reputation: 14695
You can move the cursor to the following line like so:
std::cout << "\n";
std::cout << std::endl;
The endl
option will force the stream to flush, as well.
Your code might then look like:
product = num1 * num2;
difference = num1 - num2;
std::cout << " The product is: " << product << "\n";
std::cout << " The difference is " << difference << std::endl;
Upvotes: 2
Reputation: 34574
Put this between each line or at the end of your lines or in the string you are printing.
std::cout << "\n";
Or add << endl;
at the end of each output line.
Added example for you below with the \n
.
#include <iostream> //io from console
int main() //app entry point
{
int num1; //first variabe
int num2; //second variable
int sum; //sum of 2 variabes
int product; //product of 2 variabes
int difference; //differencr of 2 variabes
int quotient; //quotient of 2 variabe
std::cout << "\nEnter first number: "; //prompt user for input
std::cin >> num1; //assigns input to num1
std::cout << "\nEnter second number "; //prompt user for input
std::cin >> num2; //assigns inout to num2
sum = num1 + num2; //calcs the sum
std::cout << "\nThe sum is " << sum; //displays the sum
product = num1 * num2; //calcs the product
std::cout << "\n The product is " << product; //displays the product
difference = num1 - num2; //calcs the product
std::cout << "\n The difference is " << difference; //displays the difference
quotient = num1 / num2; //calcs the quotient
std::cout << "\n The quotient is " << quotient; //displays the quotient
}
Upvotes: 4