Extracting and comparing numbers

This is a discussion on Extracting and comparing numbers within the C++ Programming forums, part of the General Programming Boards category; Ok I found the solution. I initialized 'total' (my int for finding the combined total of all numbers) to equal ...

  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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,457
    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.

Page 4 of 4 FirstFirst 1234
Popular pages Recent additions subscribe to a feed

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