Author Topic: Why doesn't this work? C++  (Read 2115 times)

Offline Zexion

  • Addicted to LoL
  • Chaos User
  • ******
  • Posts: 1518
  • LV: 69
  • Gender: Male
  • My anaconda don't...jk it does
    • View Profile
Why doesn't this work? C++
« on: February 06, 2013, 03:18:30 AM »
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

Offline KK20

  • Master Scripter Fixer
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3095
  • LV: 374
  • Gender: Male
  • Choco Octo <3
    • View Profile
Re: Why doesn't this work? C++
« Reply #1 on: February 06, 2013, 03:45:57 AM »
You made it one giant if-else block rather than individual if-statements.
Code: [Select]
if A
  //Do something here
else if B
  //Do something else here
else if C
  //i dunno lulz
is different than
Code: [Select]
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 AceUpgrade RMXP to RMVXA performance!
XPA TilemapTilemap rewrite with many features, including custom resolution!


NNID: KK20-CP
Discord: KK20 Tyler#8901

Offline Zexion

  • Addicted to LoL
  • Chaos User
  • ******
  • Posts: 1518
  • LV: 69
  • Gender: Male
  • My anaconda don't...jk it does
    • View Profile
Re: Why doesn't this work? C++
« Reply #2 on: February 06, 2013, 03:53:00 AM »
God I'm such a noob..
(click to show/hide)

Edit: Wouldn't the condition in the main loop (start <= end) cover me for if (start < end)?
« Last Edit: February 06, 2013, 03:54:56 AM by Zexion »

Offline KK20

  • Master Scripter Fixer
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3095
  • LV: 374
  • Gender: Male
  • Choco Octo <3
    • View Profile
Re: Why doesn't this work? C++
« Reply #3 on: February 06, 2013, 04:03:18 AM »
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 AceUpgrade RMXP to RMVXA performance!
XPA TilemapTilemap rewrite with many features, including custom resolution!


NNID: KK20-CP
Discord: KK20 Tyler#8901

Offline Zexion

  • Addicted to LoL
  • Chaos User
  • ******
  • Posts: 1518
  • LV: 69
  • Gender: Male
  • My anaconda don't...jk it does
    • View Profile
Re: Why doesn't this work? C++
« Reply #4 on: February 06, 2013, 04:04:49 AM »
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:
Code: [Select]
#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");
}
« Last Edit: February 06, 2013, 04:15:07 AM by Zexion »

Offline KK20

  • Master Scripter Fixer
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3095
  • LV: 374
  • Gender: Male
  • Choco Octo <3
    • View Profile
Re: Why doesn't this work? C++
« Reply #5 on: February 06, 2013, 04:13:04 AM »
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 AceUpgrade RMXP to RMVXA performance!
XPA TilemapTilemap rewrite with many features, including custom resolution!


NNID: KK20-CP
Discord: KK20 Tyler#8901

Offline Zexion

  • Addicted to LoL
  • Chaos User
  • ******
  • Posts: 1518
  • LV: 69
  • Gender: Male
  • My anaconda don't...jk it does
    • View Profile
Re: Why doesn't this work? C++
« Reply #6 on: February 06, 2013, 04:16:11 AM »
That makes sense lol :P I was a little confuzzled  :???:

I wanna keep messing with it though.