Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 28-11-2011
Member
 
Join Date: Nov 2011
Posts: 2
Urgent C++ program won't work correctly

I am having trouble with my program. I have been working on it for the last couple of days. I am supposed to use Simpson's rule but I am having trouble implementing it into my program.
You have to input:
road length= 1000
road width= 75
measure points= 11
enter for y value : 0, 6, 10, 13, 17, 22, 25, 20, 13, 5, 0
the answer is supposed to be 985000 cu. ft. but I keep getting 982500.0 cu. ft.

Here is the code:
Code:
#include <iostream>
#include <conio.h>
#include <math.h>
#include <iomanip>

using namespace std;
// Prototyptes
double SimsonArea(int, double);

int main()
{
    int NumPoints, RdWidth;
    double RdLength, HillCrossSectionalArea, DirtVolume;
    char Usrp;
    
    do
    {
         system("CLS");
         cout << "\n\n";
   
         cout <<"\nEnter the length of roadway through the hill:";
         cin >> RdLength;
         cout <<"\n      Enter the width of the roadway:";
         cin >> RdWidth;
         cout <<"\nEnter the number of points at which hill";
         cout <<"\n          elevation was measured:";
         cin >> NumPoints;
         cout <<"\nEnter the hill elevations(y values) at the";
         cout <<endl << NumPoints << " equally-spaced points:";
         cout <<"\n\n";
         
         HillCrossSectionalArea = SimsonArea(NumPoints,RdLength);
         
         DirtVolume = RdWidth * HillCrossSectionalArea;
         
         cout << setprecision(1) << fixed << showpoint;
         cout << "\n\n";
         cout << "---> The volume of dirt to be removed is";
         cout << "\n  Approximately " << DirtVolume << " cubic units.";
         
         cin.ignore();
         cout << "\n\n\n\t Do Another (Y or N):";
         cin.get(Usrp);
         Usrp = toupper(Usrp);
         
         } while (Usrp == 'Y');
         
         }
         
         
        
         
         double SimsonArea (int n, double length)
         {
                double sum = 0, yValue, deltaX;
                
            for(int i = 0; i <= n-1; i++)
            {
                    cout <<"Enter y value #" <<i+1 <<":";
                    cin >> yValue;
                    if(i==0 || i==n)
                       sum += yValue*4.0;
                      else
                        sum+=yValue;
            }
            
            deltaX=length/static_cast<double>(n-1);
            return deltaX*sum;
            
            }
Reply With Quote
  #2  
Old 28-11-2011
Member
 
Join Date: Nov 2011
Posts: 2
Re: Urgent C++ program won't work correctly

This is my new function for the code but now it gives me 665000 cubic units.
Code:
double SimsonArea (int n, double length)
         {
                double sum = 0, yValue, deltaX;
                
            for(int i = 0; i <= n-1; i++)
            {
                    cout <<"Enter y value #" <<i+1 <<":";
                    cin >> yValue;
                    
                    if(i==0 && i==n)
                       sum+=yValue*4.0;
                      else
                        sum+=yValue*2.0;
                      
            }
            deltaX=length/static_cast<double>(n-1);
            deltaX/=3.0;
            return deltaX*sum;
            
            }
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Urgent C++ program won't work correctly"
Thread Thread Starter Forum Replies Last Post
How to Write a program to communicate between two processes using the pipe{ This is urgent so please help me} huyleuit Software Development 1 11-11-2011 04:46 AM
Error: notification dll is not available, program will not work correctly Gorochana Operating Systems 6 12-03-2011 05:13 PM
wireless configuration-notification dll has not been registered, program will not work correctly. jhess56 Networking & Security 3 13-05-2010 04:48 AM
Sound will not work - Urgent, please help namita_ruhela25 Hardware Peripherals 4 24-12-2009 10:54 AM
When I start a program, nothing happens [URGENT!] Espz Windows Software 3 14-12-2009 12:58 AM


All times are GMT +5.5. The time now is 05:23 AM.