0

If I wanted to post an equation to make it readable, how would I do so ? Or.. how do I print spaces ' ' ?

Ex. #include <iostream> using namespace std; int main () int a = 6 for (int b = 1; b < 21; b++) { /* What would I put here to out a x b = sum ?? */ sum = a * b; cout << sum << endl;

6th Dec 2016, 2:46 AM
Ash Ketchum
Ash Ketchum - avatar
7 Antworten
+ 2
cout<<"a("<<a<<") * c("<<c<<") = sum("<<sum<<")"; try this out this will show a(value of a) * c(value of c) =sum(value of sum)
6th Dec 2016, 3:15 AM
Nikhil Dhama
Nikhil Dhama - avatar
+ 1
if you want sum for all values of a and b( as you r using for loop) then write sum+=a*b; if you want tab space just write cout<<"\t"; or if you want each output in separate line write cout<<endl; or cout<<"\n";
6th Dec 2016, 2:50 AM
Nikhil Dhama
Nikhil Dhama - avatar
+ 1
just write int a=6; int c=1; sum=a*c; cout<<sum; or if you want in the way u write then it will show a compile error, (if you write as a*b=sum; it is a wrong statement)
6th Dec 2016, 3:03 AM
Nikhil Dhama
Nikhil Dhama - avatar
+ 1
sorry but how r u introducing strings here? and where u want to use it?
6th Dec 2016, 3:04 AM
Nikhil Dhama
Nikhil Dhama - avatar
0
Thank for the info but I'm trying to figure out how to output a(6) x b(1) = sum(6), I'm not that far in C++ so the only way I see right now is to use chars.
6th Dec 2016, 2:58 AM
Ash Ketchum
Ash Ketchum - avatar
0
How do I output the variables while also outputting the sum ? That's what I'm trying to find out. a * b = sum b = 1 a = 6 So how do I output a(6) "x" b(1) "=" sum(6) The way I tried above made an error, so how else do I output x and = ? (With spaces between)
6th Dec 2016, 3:08 AM
Ash Ketchum
Ash Ketchum - avatar
0
Thank you ! Finally got it to work :D
6th Dec 2016, 3:31 AM
Ash Ketchum
Ash Ketchum - avatar