Thread: Extracting and comparing numbers

  1. #46
    Registered User
    Join Date
    Oct 2010
    Posts
    79
    Ok I found the solution. I initialized 'total' (my int for finding the combined total of all numbers) to equal 0 then I did this:

    Code:
    if( num != 0 ){
    		while (num != 0){
    		
    		currentNum = num % 10;
    		num /= 10;
    
    		cout <<"curr:" << currentNum << endl;
    			total += currentNum;
    			cout<< "total:" << total << endl;
    			
    		if( currentNum > largeNum ){
    			largeNum = currentNum;
    			
    		}
    		if( currentNum < smallNum ){
    			smallNum = currentNum;
    		}
    		
    		}
    	}
    	else{
    		largeNum = 0;
    		smallNum = 0;
    		total = 0;
    	}

  2. #47
    Registered User
    Join Date
    Oct 2010
    Posts
    79
    Thanks a lot for all the help and the time you took out to help me. It probably took a lot of patience to put up with my amateurism. Thanks again!

  3. #48
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Don't forget those logic lessons now. They weren't meant to solve the problem, but rather to enable you to think like a computer to solve any general problem.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed