Why doesn't this work? C++

Started by Zexion, February 05, 2013, 08:18:30 pm

Previous topic - Next topic

Zexion

Okay so basically you have to enter the starting time , increments (in hours) and ending time.. if you do it right, then it works, but if you don't then it either ignores the rules i set, or does the wrong one??

start cant be > than 48 neither can end, AND they can't be equal..
also the increments cannot be greater than the end time, and also cannot be greater than 48..

Take a look: https://dl.dropbox.com/u/59018752/asgn.cpp

KK20

You made it one giant if-else block rather than individual if-statements.

if A
  //Do something here
else if B
  //Do something else here
else if C
  //i dunno lulz

is different than

if A
  //Do something here
if B
  //Do something else here
if C
  //i dunno lulz


What about the condition of start < end? Also, what if the user inputs a value that STILL doesn't satisfy the conditions a second time? You don't have any form of loop to check this.

I'll let you to figure that out. :P

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Zexion

February 05, 2013, 08:53:00 pm #2 Last Edit: February 05, 2013, 08:54:56 pm by Zexion
God I'm such a noob..
Spoiler: ShowHide
Also, why the fk is my avatar still noctis lolol


Edit: Wouldn't the condition in the main loop (start <= end) cover me for if (start < end)?

KK20

I guess. It's just weird that it prints "Time", "Altitude (m)", and "Velocity (m/s)" like it's going to do some calculations, but the program just stops. My personal preference, but if the assignment allows it then by all means keep it as is.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Zexion

February 05, 2013, 09:04:49 pm #4 Last Edit: February 05, 2013, 09:15:07 pm by Zexion
Well that's actually the problem :P if you type it right, eg: start: 0 incr: 1 end: 5 then it works right, but if you purposely make an error like making start >48 then it will start spazzing.

Well I'm just going to turn it in the boring way :P in reality the assignment says to make the calculations in table format, and end can't be greater than 48, but I wanted to make it more logical and require that start also be less than 48 and not equal to end etc.

final code:
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

main()
{     
      int incr=0;
      double start=0.0, end=0.0, alt=0.0, vel=0.0;
     
      cout << "Type the starting time, increments, and ending time in hours: ";
      cin >> start >> incr >> end;
      while (end > 48) {
          cout << "The maximum end time is 48." << endl << "Please type another end time." << endl;
          cin >> end;
                     }   
      cout << "Time" << setw(20) << "Altitude (m)" << setw(22) << "Velocity (m/s)" << endl;
      while ( start <= end )
      {
           alt = ((-0.12 * pow(start,4)) + (12 * pow(start,3)) - (380 * pow(start,2)) + (4100 * start) + 220);
           vel = ((-0.48 * pow(start,3)) + (36 * pow(start,2)) - (760 * start) + 4100) / 3600;
           cout << setprecision(0) << setw(2) << start << setprecision(2) << fixed << setw(20) << alt << setw(20) << vel << endl;
           start += incr;
      }
      system("pause");
}

KK20

Oh shit, I meant to say start > end.
And I was telling myself the whole time while typing to not make that mistake.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Zexion

That makes sense lol :P I was a little confuzzled  :???:

I wanna keep messing with it though.