Does this seems right???

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
cout << fixed << setprecision(1);

float time;
float acceleration;
double distance;

time = 10.0;
acceleration = 60.0;
distance = 3000;

cout << "The time was: 10.0 sec.\n";
cout << "The acceleration was: 60.0 feet/sec/sec.\n";
cout << "The distance traveled was: " << distance << "feet.\n";
system("pause");
return 0;
Don't you want the cout statements to output the values of the variables, not a static value? Distance looks correct, the other two are just cout'ing "10.0 sec" or "60.0 feet/sec/sec". Also, you need a curly bracket at the very end of the program to close out main().
so i should delete the other two?
You are not displaying the actual variables in your cout statement you are hardcoding them in with the string you have entered.. You got the 3rd cout statement right with the distance variable included but you didn't include the other 2 variables in the previous cout statements.?

1
2
3
4
 
    cout << "The time was: "<< time << "sec.\n";
    cout << "The acceleration was: "<<  acceleration << " feet/sec/sec.\n";
    cout << "The distance traveled was: " << distance << "feet.\n";
Last edited on
Great! Thanks for your help! And lastly, does that cout << fixed.....in right place? Thanks
It does work where it is located but I wouldn't say its in the right place because it looks messy. Try to group things together by their function...
Such as, try to group necessary variables on top. Group the output statements together

so like


1
2
3
4
5
    cout << fixed << setprecision(2);
    cout << "The time was: "<< time << "sec.\n";
    cout << "The acceleration was: "<<  acceleration << " feet/sec/sec.\n";
    cout << "The distance traveled was: " << distance << "feet.\n";
    



Set precision works by limiting the number of decimal places to the specified value. So I set this at 2 ..so it will show 2 places to the right of the decimal.

Ex) 2.00

if you set 3

2.000

and so on.
Last edited on
Thank you soooo much!!! and im really sorry to bother you but i have 1 more question to ask. I've been looking around google and couldn't find the exact answer that im looking for. How would i code the shapes? im not talking about colums and rows but something like this:
(suppose to be arrow pointing up..)


1
2
3
4
5
6
7
8
                          
           *                                       
          ***                                    
         *****            
           *                 
           *
           *
           *          

Last edited on
ill give you a hint...


cout << "*" << endl;
Topic archived. No new replies allowed.