Like Tree2Likes

3 small char problems

This is a discussion on 3 small char problems within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by rags_to_riches Odd...CS 575 implies that you are not an amateur or a beginner, as stated in your ...

  1. #16
    Registered User
    Join Date
    Sep 2011
    Posts
    11
    Quote Originally Posted by rags_to_riches View Post
    Odd...CS 575 implies that you are not an amateur or a beginner, as stated in your first post. Does your school do something wacky, like start you off in 500-level courses, with 100-levels being the final year courses? Just a non-standard nomenclature, AFAIK. Heck, most 500-level courses are grad school courses.

    (Just an aside...oddities fascinate me)
    well the college I go to offers many programming classes, the teachers itself do make fun of the classes as my next semmester class is cs 570 which is java but you start at 575 which gives you the abcs of programming in which i am stuck

  2. #17
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Quote Originally Posted by elpedoloco View Post
    Awesome, so for my problem I understand that:
    x takes value of 100s
    y takes value of 10s and
    z takes value of 1s

    I tried to do the conversion as follows
    digit =(x+100)+(y+10)+(z+1) however my silly attempt did not work.
    It would be (x * 100) + .... Come on now, turn your brain on.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  3. #18
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,652
    Your school is weird

  4. #19
    Registered User
    Join Date
    Sep 2011
    Posts
    11
    Quote Originally Posted by AndrewHunter View Post
    It would be (x * 100) + .... Come on now, turn your brain on.
    Sorry Andrew, I do appreciate your help, I am just getting some weird compiler outputs I keep getting big numbers;
    I understood how each character takes place depending on the digit and thus we must multiply that char by its digit, however I know that I must tell the compiler to
    perform an operation with the asquii code overall numbers so it does not confuse my value for one of theirs.
    Thats where I am currently stuck at the moment, Thanks again Andrew you've been greater help than my teacher.

    Code:
    
    
    //  CS 575 HW 3 
    
    #include <iostream>
    #include <string>
    using namespace std;
    
    
    void c();
    void d();
    void e();
    void f();
    void g();
    void h();
    
    bool die( const string & msg );
    
    int main(){
    
    
        c();
        d();
        e();
        f();
        g();
        h();
    
    }
    
    
    
    void c(){
    	 char x,y,z;
         int digit;
         cin>>x>>y>>z;
    	 digit=(x*100)+(y*10)+(z*1); // this operation seems to get the value of asquii code of a,b,c and then multiply by 100,10,1
         cout << digit;
    		
    }    //  c
    
    void d(){
    
    }    //  d
    
    void e(){
    }    //  e
    
    void f(){
      
    }    //  f
    
    void g(){
      
    }    //  g
    
    void h(){
    }    //  h
    
    
    bool die( const string & msg ){
        cerr <<endl <<"Fatal error: " <<msg <<endl;
        exit( EXIT_FAILURE );
    }   //  die



  5. #20
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    I see what you are saying now. A simple ASCII to decimal conversion is to subtract '0' from the number. So if you have char '5', to get number 5 you would do: '5'-'0'.( That is the char zero. )So in your case:

    ((x-'0')*100) + ....
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  6. #21
    Registered User
    Join Date
    Sep 2011
    Posts
    11
    Quote Originally Posted by AndrewHunter View Post
    I see what you are saying now. A simple ASCII to decimal conversion is to subtract '0' from the number. So if you have char '5', to get number 5 you would do: '5'-'0'.( That is the char zero. )So in your case:

    ((x-'0')*100) + ....
    Thanks Andrew you been great help.

  7. #22
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    a,b,c,d,e,f,g,h ... best function names ever!
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  8. #23
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Quote Originally Posted by iMalc View Post
    a,b,c,d,e,f,g,h ... best function names ever!
    It correlates with his assignments. I don't think he has a choice.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

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

Similar Threads

  1. One small doubt with char pointer
    By dipesh.nomad in forum C Programming
    Replies: 6
    Last Post: 07-23-2011, 10:18 PM
  2. small problems .. need help ..
    By Kawaii JoJo in forum C++ Programming
    Replies: 5
    Last Post: 11-13-2009, 03:00 AM
  3. Problems, small program- HELP!
    By ProgrammingDlux in forum C++ Programming
    Replies: 2
    Last Post: 03-01-2002, 09:08 AM
  4. 2 small problems
    By Robert_Ingleby in forum Windows Programming
    Replies: 3
    Last Post: 11-21-2001, 06:16 AM

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