2011-01-06 19 views
13

मैं प्रोग्रामिंग के लिए नया हूं और एक नया प्रोग्राम लिखने की कोशिश कर रहा हूं। मेरे प्रोग्राम के माध्यम से जांच करते समय यह त्रुटि कोड 1 लौटा रहा है। # क्यूएनएएन। मैंने परिवर्तनीय को अलग करने और उत्तरों के लिए शोध करने की कोशिश की है लेकिन कोई समाधान नहीं मिल रहा है।1. # क्यूएनएएन त्रुटि सी ++

मेरे कोड:

// This is a program to decide what culvert should be properly used for a specific installation 
// using given measurements and data 
// 
#include <cstdio> 
#include <cstdlib> 
#include <iostream> 
#include <string> 

using namespace std; 
// initializing functions 
double slope_function(); 
double cbasin(); 
// initializing classes: Subdivisions specs 

//intitializing global variables 
double edge_road =0; 
double up_stream =0; 
double down_stream =0; 
double tbm =0.0; 

//double culv_length =0; 
double slope = 0.0 ; 
char street_name[1001]; 
int min_culv = 15; 
double up_strm_culv =0; 
double dwn_strm_culv =0; 


int main (int nNumberofArgs, char* pszArgs[]) 
{ 
    cout<< "This program will allow the surveyor to double check their calculations\n"; 
    cout << "in deciding what size, type, and requirements are allowed for the\n"; 
    cout << "installation of culverts in Terrebonne Parish.\n\n"; 



// begin input 
    cout << "what is the name of the street\nwhere the culverts will be installed: "; 
    cin.getline (street_name,1000); 
    cout << endl; 
    cout << "What is the Benchmark: "; 
    cin >> tbm; 
    cout << endl; 
    cout << "What is the elevation of the edge of the road: "; 
    cin >> edge_road; 
    cout << endl; 
    cout << "What is the up-stream culvert size: "; 
    cin >> up_strm_culv; 
    cout << endl; 
    cout << "What is the culverts up-stream inverted elevation: "; 
    cin >> up_stream; 
    cout << endl; 
    cout << "What is the down-stream culvert size: "; 
    cin >> dwn_strm_culv; 
    cout << endl; 
    cout << "What is the culverts down-stream inverted elevation: "; 
    cin >> down_stream; 
    cout << endl; 
    cout << "What is the length of culvert requested: "; 
    cin >> culv_length; 


    cout << "Your slope is : "; 
    cout << slope_function(); 
    cout << endl; 
    cout << street_name; 
    cout << endl; 
    cout << cbasin(); 


    cout << endl; 
    // wait until user is ready before terminating program 
    // to allow the user to see the program results 
    system ("pause"); 
    return 0; 
} 

// slope function 
double slope_function() 
{ 
    double riseoverrun = 0.0; 
    slope = (up_stream - down_stream)/ culv_length; 
    return slope; 
} 


// Catch Basin function 
double cbasin () 
{ 
    double cb = 0; 
    cb = culv_length/60; 
    cout << endl; 
    cout << "You need "; 
    cout << cb; 
    cout << " catch basins for this job."; 
    cout << endl; 
} 
+1

आपके द्वारा लिंक किया गया कोड संकलित नहीं करता है। लेकिन यहां तक ​​कि यदि यह भाग गया तो भी आप 0 से 0 को विभाजित कर रहे हैं जिसकी अनुमति नहीं है। –

+1

मैंने एनएएन का विवरण दिया है लेकिन आपकी वास्तविक बग एक ऐसा फ़ंक्शन है जो डबल लौटाता है लेकिन उसके पास कोई रिटर्न स्टेटमेंट नहीं है। – CashCow

उत्तर

42

1 # QNAN "शांत नेन" के लिए एक स्ट्रिंग प्रतिनिधित्व है। एक "एनएएन" "संख्या-संख्या" नहीं है और केवल फ्लोट्स और युगल पर लागू होता है।

एनएएन वास्तव में "शून्य" मानों का प्रतिनिधित्व करने के लिए बहुत उपयोगी हो सकता है (कुछ वास्तविक संख्या चुनने के बजाय और सबसे अच्छा उम्मीद है कि आपको उस प्राकृतिक अर्थ के लिए उस नंबर की आवश्यकता नहीं है)।

ऑपरेशन "मान्य नहीं है" (उदाहरण के लिए ऋणात्मक संख्या का लॉग लेना) कुछ गणितीय परिचालन एक नैन वापस कर सकते हैं।

आप C++ से एक QNAN उत्पन्न

double d = std::numeric_limits<double>::quiet_NaN(); 

किसी भी तुलना आपरेशन का उपयोग कर सकते हैं (==, < = आदि) एक नेन पर झूठी देता है, यहां तक ​​कि, जो अपने आप को इसकी समानता की तुलना के लिए छोड़कर! = जो हमेशा रिटर्न सच (यहां तक ​​कि तुलना करने पर भी)।

(आपके कोड में वास्तविक बग एक ऐसा फ़ंक्शन प्रतीत होता है जो डबल लौटाता है लेकिन इसमें कोई वापसी विवरण नहीं होता है)।

+1

यह निर्धारित करने के लिए एक अच्छा कार्य है कि कोई मान नैन होगा: 'टेम्पलेट <टाइपनाम VAL> बूल is_ieee_nan (कॉन्स वैल और वी) {वापसी! (V == v); } ' –

+0

आपको '! =' हमेशा कहां मिल रहा है? –

+0

एक बहुत ही अजीब और बेकार विशेषता की तरह लगता है। यदि आप एनएएन का पता नहीं लगा सकते हैं, तो यह कितना अच्छा है? –

संबंधित मुद्दे