octal number problem ...

This is a discussion on octal number problem ... within the C++ Programming forums, part of the General Programming Boards category; post the code where the error occurs......

  1. #16
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    post the code where the error occurs...
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  2. #17
    Registered User
    Join Date
    Jan 2006
    Posts
    141
    can i send you my code via email./. this is my assignment and just in case someone plagiarism .. please

  3. #18
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    Perhaps you could just post the line that the error refers to and the declaration of the variable or function that is being used.

  4. #19
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    can i send you my code via email./. this is my assignment and just in case someone plagiarism .. please
    Sure. I'd love to see it. But if you want a reply, post it here.

    Most likely you're trying to assign dec_to_oct() to an integer variable. You can't. (to quote chaosengine) An Int Is An Int Is An Int™
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  5. #20
    Registered User
    Join Date
    Jan 2006
    Posts
    141
    ok here is the problem that occur in my program now....

    the day = 29.

    Code:
    int sqrtOfMonth(double month); //square root of month's function
    int numPrimeFactor(int year); //number of prime factors of the year's function
    int largestPrimeFactor(int year); //largest prime factor's function
    int octalDay(int day); //base 8 representation of the day's function
    int sqrDigitLen(int day); //squared digit length of the day's function
    string IntToString(int year, int month, int day, int counter); //convert int to string function
    
    
    
    int main()
    {
        int month;
        int year, day;
        int counter = 0;
        
    //prompt user input    
        cout<<"Please enter your date of birth [dd mm yyyy]: ";
        cin>>day>>month>>year;
        
    //display the function from question A - E  
      
        cout<<sqrtOfMonth(month)<<endl;
        cout<<numPrimeFactor(year)<<endl;
        cout<<largestPrimeFactor(year)<<endl;
        cout<<octalDay(day)<<endl;
        
        
    //find the squared digit length
    
        while(day > 10) 
        {
            day = sqrDigitLen(day);
            counter++;
        }
        cout<<counter<<endl;
    
    //display string
    
        string  result = IntToString(year, month, day, counter);
        cout << result << endl;
    	
        system ("pause");
        return 0;
    }
    
    int octalDay(int day)
    {
        cout.flags(ios_base::oct);
        return day;
    }
    
    //convert integer into string
    
    string IntToString(int year, int month, int day, int counter)
    {
        ostringstream myStream; //creates an ostringstream object
        myStream <<sqrtOfMonth(month)<<numPrimeFactor(year)<<largestPrimeFactor(year)<<octalDay(day)<<counter;
      
        return(myStream.str()); //returns the string form of the stringstream object
    }
    the input is of the day is 29
    and the output of the first line cout is correct which is 35..

    but when i output as string, the numbers turns to 34....

    can some one let me know what is the problem please

  6. #21
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Code:
    int octalDay(int day)
    {
        cout.flags(ios_base::oct);
        return day;
    }
    well, to begin with, if you aren't going to pay attention to the answers you've already been given, there isn't much chance you'll benefit from additional advice. second, you don't even provide all of the relevent code needed to pinpoint the problem (what does sqrDigitLen do?).
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  7. #22
    Registered User
    Join Date
    Jan 2006
    Posts
    141
    i am sorry but and this is the code here...

    Code:
    int octalDay(int day); //base 8 representation of the day's function
    string IntToString(int year, int month, int day, int counter); //convert int to string function
    
    
    
    int main()
    {
        int month;
        int year, day;
        int counter = 0;
        
    //prompt user input    
        cout<<"Please enter your date of birth [dd mm yyyy]: ";
        cin>>day>>month>>year;
        
    //display the function from question A - E  
      
        cout<<octalDay(day)<<endl;
        
    
    //display string
    
        string  result = IntToString(year, month, day, counter);
        cout << result << endl;
    	
        system ("pause");
        return 0;
    }
    
    int octalDay(int day)
    {
        cout.flags(ios_base::oct);
        return day;
    }
    
    //convert integer into string
    
    string IntToString(int year, int month, int day, int counter)
    {
        ostringstream myStream; //creates an ostringstream object
        myStream <<octalDay(day);
      
        return(myStream.str()); //returns the string form of the stringstream object
    }
    the output come out from the first cout is what i want which is 35. but when i input into the string, the second cout turns into 29.

    can someone point out the problem please...really appreciated

  8. #23
    Registered User
    Join Date
    Apr 2006
    Posts
    22

    Talking good luck

    isn't that anoying? if what you're trying to do is output a number in textual form, There is no function in c++ for that, sorry. if you want to convert a number to the octal form, then create a function for it. However, you can make a program to change numbers into text, do like a calculator, only deal with one - nine and the different places up to the largest known number which is 999,999,999,999,999 ( or nine-hundred ninty-nine trillion, nine-hundred ninty-nine billion, nine-hundred ninty-nine million, nine-hundred ninty-nine thousand, nine-hundred ninty-nine ). Of course, using this method there's no reason you can't make up numbers and go forever.

  9. #24
    Registered User
    Join Date
    Apr 2006
    Posts
    22

    Talking

    Quote Originally Posted by peter_hii
    i am sorry but and this is the code here...

    Code:
     
    int octalDay(int day); //base 8 representation of the day's function
    string IntToString(int year, int month, int day, int counter); //convert int to string function
     
     
     
    int main()
    {
    int month;
    int year, day;
    int counter = 0;
     
    //prompt user input 
    cout<<"Please enter your date of birth [dd mm yyyy]: ";
    cin>>day>>month>>year;
     
    //display the function from question A - E 
     
    cout<<octalDay(day)<<endl;
     
     
    //display string
     
    string result = IntToString(year, month, day, counter);
    cout << result << endl;
     
    system ("pause");
    return 0;
    }
     
    int octalDay(int day)
    {
    cout.flags(ios_base::oct);
    return day;
    }
     
    //convert integer into string
     
    string IntToString(int year, int month, int day, int counter)
    {
    ostringstream myStream; //creates an ostringstream object
    myStream <<octalDay(day);
     
    return(myStream.str()); //returns the string form of the stringstream object
    }
    the output come out from the first cout is what i want which is 35. but when i input into the string, the second cout turns into 29.

    can someone point out the problem please...really appreciated
    here's a hint, 29 is the decimal form of the octal number 35

  10. #25
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> the output come out from the first cout is what i want which is 35. but when i input into the string, the second cout turns into 29.

    you ask a question, you get an answer. you ask the same question, you get another answer. you ask the same question again...what's the point?

    1) STATE the problem as clearly as possible
    2) READ the responses thoroughly
    3) ASK about what you don't understand
    4) TRY to solve the problem on your own
    5) REPEAT step 2, if necessary
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 11:13 AM
  2. Random Number Range Problem.
    By xamlit in forum C Programming
    Replies: 11
    Last Post: 01-26-2006, 12:55 PM
  3. small problem
    By ucfmustang in forum C Programming
    Replies: 1
    Last Post: 02-10-2003, 04:55 PM
  4. number ouput problem...
    By o0obruceleeo0o in forum C++ Programming
    Replies: 7
    Last Post: 11-17-2002, 06:56 AM
  5. problem with my prime number program
    By datainjector in forum C Programming
    Replies: 4
    Last Post: 07-12-2002, 01:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21