Loop Not Working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Prosdo
    New Member
    • Nov 2007
    • 32

    #16
    Originally posted by Ganon11
    It's ios::fixed and ios::showpoint, not ios||fixed and ios||showpoint. The || is used to sort of link the two flags together so that both are passed to the function.
    I can't get it to just show one decimal point for the height. I don't know what I'm doing wrong.
    Code:
    #include <iostream.h>
    #include <stdlib.h>
    #include <cmath>
    #include <iomanip>
    #include <fstream>
    
    using namespace std;
    float const gravity = 9.8;
    float velocity;
    float seconds;
    float height;
    ofstream launch;
    
    int main()
    {
    launch.open("C:\\Documents and Settings\\All Users\\Desktop\\launch.dat");
    launch<<setw(13)<<"Time(Seconds)"<<setw(8)<<" "<<setw(14)<<"Height(Meters/Seconds Squared)"<<'\n'<<'\n';
    cout<<"Please enter the the launch velocity in meters/seconds squared."<<'\n';
    cin>>velocity;
    seconds=1;
    height=0;
    launch.setf(ios::showpoint||ios::fixed);
    launch<<setprecision(2);
    for(seconds=1;height >= 0;seconds++)
    {
    height = velocity * seconds - (1.0/2.0 * gravity * pow(seconds,2));
    if (height<0)
    launch<<setw(2)<<seconds<<setw(8)<<" "<<setw(10)<<0<<'\n';
    else
    launch<<setw(2)<<seconds<<setw(8)<<" "<<setw(10)<<height<<'\n';
    }
    launch.unsetf(ios::showpoint||ios::fixed);
    launch.close();
          system("PAUSE");
          return 0;
    }

    Comment

    • Prosdo
      New Member
      • Nov 2007
      • 32

      #17
      I tried changing the precision numbers but it made it just sent things crazy lol.

      Comment

      • Ganon11
        Recognized Expert Specialist
        • Oct 2006
        • 3651

        #18
        Whoops; instead of launch.setf(ios ::showpoint||io s::fixed), try launch.setf(ios ::showpoint|ios ::fixed), then change setprecision's value to 1.

        Comment

        • Prosdo
          New Member
          • Nov 2007
          • 32

          #19
          Originally posted by Ganon11
          Whoops; instead of launch.setf(ios ::showpoint||io s::fixed), try launch.setf(ios ::showpoint|ios ::fixed), then change setprecision's value to 1.
          Thanks so much that was driving me crazy. You are a life saver!

          Comment

          Working...