Thread: my program show inf. how???

  1. #1
    Registered User
    Join Date
    Aug 2020
    Posts
    2

    my program show inf. how???

    my program show inf. how???-p1-2-jpgmy program show inf. how???-p2-jpg

    Code:
    this is my code:
    #include <iostream>
    #include <iomanip>
    #include <cmath>
    
    
    using namespace std;
    
    
    int main()
    {
        const double PI=3.142; 
        const double H=6.626E-34;
        const double C=2.998E+08;
        const double K=1.381E-23;
        
        char character;
        double i,u1,u2,u3,u4,u5,u6,u7,u8,p,temperature_in_Kelvin,surface_area_millimeter_square;
        int type_of_spectrum,lower_wavelength_range,upper_wavelenght_range;
        
        cout<<"Black body radiation "<<endl;
        cout<<"--------------------"<<endl;
        cout<<"\n\n";
            
        cout<<"Enter the type of radiation spectrum. "<<endl;
        cout<<"Visible light spectrum"<<setw(9)<< " =1"<<endl;
        cout<<"Ultraviolet spectrum"<<setw(11)<< " =2"<<endl;
        cout<<"Type of spectrum"<<setw(14)<<':';
        cin>>type_of_spectrum;
        cout<<"\n\n";
        
        while(type_of_spectrum<=0 || type_of_spectrum>2  )
        {    
            cout<<"YOU ENTER A INVALID CODE. PLEASE ENTER THE TYPE OF RADIATION SPECTRUM AGAIN."<<endl;
            cout<<"Visible light spectrum"<<setw(9)<< " =1"<<endl;
            cout<<"Ultraviolet spectrum"<<setw(11)<< " =2"<<endl;
            cout<<"Type of spectrum"<<setw(14)<<':';
            cin>>type_of_spectrum;
            cout<<"\n\n";
        }
        
        cout<<"Enter the lower limit and upper limit for the type of spectrum "<<type_of_spectrum<<" (nm)"<<endl;
        cout<<"Lower limit: ";
        cin>>lower_wavelength_range;
        cout<<"Upper limit: ";
        cin>>upper_wavelenght_range;
        cout<<"\n";
        
        if(type_of_spectrum==1)
        while (lower_wavelength_range<400 || upper_wavelenght_range>700 || lower_wavelength_range>upper_wavelenght_range) 
        {
            
            cout<<"The lower limit for visible light spectrum should be >=400."<<endl;
            cout<<"The upper limit for visible light spectrum should be <=700."<<endl;
            cout<<"Please enter the lower limit and upper limit again."<<endl;
            cout<<"Lower limit: ";
            cin>>lower_wavelength_range;
            cout<<"Upper limit: ";
            cin>>upper_wavelenght_range;
            cout<<"\n";
            
        }
        
        
        if(type_of_spectrum==2)
        while (lower_wavelength_range<10 || upper_wavelenght_range>400 || lower_wavelength_range>upper_wavelenght_range) 
        {
            cout<<"The lower limit for ultraviolet spectrum should be >=10."<<endl;
            cout<<"The upper limit for ultraviolet spectrum should be <=400."<<endl;
            cout<<"Please enter the lower limit and upper limit again."<<endl;
            cout<<"Lower limit: ";
            cin>>lower_wavelength_range;
            cout<<"Upper limit: ";
            cin>>upper_wavelenght_range;
            cout<<"\n";    
            
        }
        
        cout<<"Enter the temperature in (K): ";
        cin>>temperature_in_Kelvin;
        cout<<"Enter the radiating surface area in (mm): ";
        cin>>surface_area_millimeter_square;
        
        u1=((2*PI*H*C*C)/pow(lower_wavelength_range,5))*1/(exp((H*C)/lower_wavelength_range*K*temperature_in_Kelvin)-1);
        u2=((2*PI*H*C*C)/pow(upper_wavelenght_range,5))*1/(exp((H*C)/upper_wavelenght_range*K*temperature_in_Kelvin)-1);
        
        
        p=(u1*surface_area_millimeter_square*pow(10,-15))+(u2*surface_area_millimeter_square*pow(10,-15));
        cout<<fixed<<setprecision(5)<<u1<<endl;
    
    
        return 0;
    }
    Attached Images Attached Images my program show inf. how???-p1-jpg 

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What was your test input, expected output, and actual output?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Aug 2020
    Posts
    2
    I want to test the power with is p in my program, the expected output is 7.60161e-011 but my programme show inf

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    It's impossible to verify your formulas based on your fuzzy pictures taken from your phone.


    First off, remove useless fluff
    Code:
    baz.cpp: In function ‘int main()’:
    baz.cpp:16:10: warning: unused variable ‘character’ [-Wunused-variable]
         char character;
              ^
    baz.cpp:17:12: warning: unused variable ‘i’ [-Wunused-variable]
         double i,u1,u2,u3,u4,u5,u6,u7,u8,p,temperature_in_Kelvin,surface_area_millimeter_square;
                ^
    baz.cpp:17:20: warning: unused variable ‘u3’ [-Wunused-variable]
         double i,u1,u2,u3,u4,u5,u6,u7,u8,p,temperature_in_Kelvin,surface_area_millimeter_square;
                        ^
    baz.cpp:17:23: warning: unused variable ‘u4’ [-Wunused-variable]
         double i,u1,u2,u3,u4,u5,u6,u7,u8,p,temperature_in_Kelvin,surface_area_millimeter_square;
                           ^
    baz.cpp:17:26: warning: unused variable ‘u5’ [-Wunused-variable]
         double i,u1,u2,u3,u4,u5,u6,u7,u8,p,temperature_in_Kelvin,surface_area_millimeter_square;
                              ^
    baz.cpp:17:29: warning: unused variable ‘u6’ [-Wunused-variable]
         double i,u1,u2,u3,u4,u5,u6,u7,u8,p,temperature_in_Kelvin,surface_area_millimeter_square;
                                 ^
    baz.cpp:17:32: warning: unused variable ‘u7’ [-Wunused-variable]
         double i,u1,u2,u3,u4,u5,u6,u7,u8,p,temperature_in_Kelvin,surface_area_millimeter_square;
                                    ^
    baz.cpp:17:35: warning: unused variable ‘u8’ [-Wunused-variable]
         double i,u1,u2,u3,u4,u5,u6,u7,u8,p,temperature_in_Kelvin,surface_area_millimeter_square;
                                       ^
    baz.cpp:17:38: warning: variable ‘p’ set but not used [-Wunused-but-set-variable]
         double i,u1,u2,u3,u4,u5,u6,u7,u8,p,temperature_in_Kelvin,surface_area_millimeter_square;
                                          ^
    The last one is interesting, you calculate a p, but then just decide to print u1 anyway.

    Next, get familiar with your debugger.
    Just being able to set a breakpoint and print variables will tell you a lot.
    Code:
    $ gdb -q ./a.out
    Reading symbols from ./a.out...done.
    (gdb) b 82
    Breakpoint 1 at 0x4011b8: file baz.cpp, line 82.
    (gdb) run
    Starting program: /home/sc/Documents/a.out 
    Black body radiation 
    --------------------
    
    
    Enter the type of radiation spectrum. 
    Visible light spectrum       =1
    Ultraviolet spectrum         =2
    Type of spectrum             :1
    
    
    Enter the lower limit and upper limit for the type of spectrum 1 (nm)
    Lower limit: 400
    Upper limit: 500
    
    Enter the temperature in (K): 1000
    Enter the radiating surface area in (mm): 1
    
    Breakpoint 1, main () at baz.cpp:82
    82	    u1=((2*PI*H*C*C)/pow(lower_wavelength_range,5))*1/(exp((H*C)/lower_wavelength_range*K*temperature_in_Kelvin)-1);
    (gdb) p PI
    $1 = 3.1419999999999999
    (gdb) p H
    $2 = 6.6259999999999998e-34
    (gdb) p C
    $3 = 299800000
    (gdb) p lower_wavelength_range 
    $4 = 400
    (gdb) n
    83	    u2=((2*PI*H*C*C)/pow(upper_wavelenght_range,5))*1/(exp((H*C)/upper_wavelenght_range*K*temperature_in_Kelvin)-1);
    (gdb) p u1
    $5 = inf
    See, it's already gone wrong at u1.

    At a guess, you need more () around *1/
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why this program show me unlimited number of ans?
    By abhijitnumber1 in forum C Programming
    Replies: 1
    Last Post: 07-02-2012, 09:07 AM
  2. Program to show a multiplication table
    By Interista in forum C Programming
    Replies: 3
    Last Post: 10-19-2011, 06:19 PM
  3. show the content of a .dat file in a dos program
    By nevrax in forum C Programming
    Replies: 2
    Last Post: 04-05-2007, 05:05 PM
  4. not show my program on taskbar
    By ReXXuSS in forum C Programming
    Replies: 12
    Last Post: 08-19-2006, 03:27 AM
  5. Program doesn't show up
    By Krasimir11 in forum C Programming
    Replies: 7
    Last Post: 01-05-2006, 06:21 PM

Tags for this Thread