one thing I did notice was that the num2 was putting a remainder of 30 for 130, and I'm not too sure what I need to do to change that, without affecting the whole program.

Any help would be fantastic, thanks.

#include <iostream> #include <iomanip> #include <cmath> #include <cctype> #include <string> #include <cstdlib> using namespace std; /**************************************************************************************** Stephen Allen, CS361, Week 6, Programming assignment 6, Program 1 Program calculates the bill for a user input is number of puchases, type of iceream, amount of icecream, and number of toppings output is total for icecream by treat type, weight and topping amount Total bill amout is outputted by main I called the janitor the other day to see what he could do about my dingy linoleum floor. He said he would have been happy to loan me a polisher, but that he hadn't the slightest idea what he had done with it. I told him not to worry about it - that as a programmer it wasn't the first time I had experienced a buffer allocation failure due to a memory error. ***************************************************************************************/ // constants for max values const int MIN = 1; const int MAX = 9999; const int MAX_TERMS = 50; const int NINE = 9; const int TEN = 10; const int HUND = 100; const int THOU = 1000; // constant strings for output const string FIRST_NUM = "Enter the first number to test: "; const string LAST_NUM = "Enter the last number to test: "; const string ERROR1 = "Invalid -- must be between "; const string ERROR_AND = " and "; // prototypes int happy(); int numbers(); bool happy (int input1){ bool test = false; int sum; int num1; int num2; int num3; int num4; int num5; int div ; sum = input1; for (num1 = 0; num1 <= MAX_TERMS || sum != MIN; ++num1){ while ( num1 <= MAX_TERMS && sum != MIN){ if (sum <= 9){ div = MIN; } if (sum < 100){ div = TEN; } if (sum >= 100){ div = 100; } if (sum >= 1000){ div = 1000; } num1 = sum / div; num2 = sum % div; cout << endl; cout << num1 << endl; cout << num2 << endl; num3 = num1 * num1; num4 = num2 * num2; num5 = num3 + num4; sum = num5; cout << " " << sum << " "; } } if (sum == MIN ){ test = true; } return test; } int numbers(int& input1, int& input2){ // prompts user for input for first number cout << FIRST_NUM; cin >> input1; cout << endl; while (input1 < MIN || input1 > MAX){ cout << ERROR1 << MIN << ERROR_AND << MAX << endl; cout << FIRST_NUM; cin >> input1; } // prompts for user input for last number cout << endl; cout << LAST_NUM; cin >> input2; cout << endl; while (input2 < input1 || input2 > MAX){ cout << ERROR1 << input1 << ERROR_AND << MAX << endl; cout << LAST_NUM; cin >> input2; } return 0; } int main (){ int input; int input2; int compare_num; bool happy_num; cout << "Program to test for Happy numbers" << endl; cout << endl; // calls numbers function to get input from user numbers(input,input2); compare_num = input; while (compare_num <= input2){ happy_num = happy(compare_num); if (happy_num == 1){ cout << endl; cout << "Number is happy"; cout << endl; system ("Pause"); } else if(happy_num == 0){ cout << endl; cout << "Number is sad."; cout << endl; system ("Pause"); } ++compare_num; } system ("Pause"); return 0; }