Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Ground Controller Lvl 1
Message 1 of 2

Review my C++ project

Please find attached a copy of the c++program i have been working so i can delivery it next year as part of a programming class. I have an issue with data validation, and a stack error when i run it around the object being corrupt.

 

main.cpp

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//																																						//
//																	Count Down Application																//										
//																	Written by CJ Harrison (11/06/2019)													//
//																																						//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//																																						//
//	A counting application designed to asked the users to enter into the system hours, minutes and seconds. The application converts this into			//
//  seconds. A while loop and will add one to the clock until it equals the total number of seconds entered into the application.						//
//																																						//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include "countdown.h"
#include <iostream>
using namespace std;


void main()
{
	cout << "Welcome to a count down application that counts down in seconds.\nBased upon the number of hours, minutes and seconds you enter.\n\n";
	
	countdown cDown;

	cDown.vEntry();
	cDown.timecal();
	cDown.clock();

	
}

countdown.h

#ifndef _COUNTDOWN_H_
#define _COUNTDOWN_H_

class countdown
{
public:

	//Long Long integers used to work with bigger numbrs that a regular integer
	long long int tHours, tMinutes, tSeconds, tClock = 0;
	

	void vEntry();
	
	void clock();

//private:
	long long int tTime[2]; //Array used to store the total number of Seconds
	
	void timecal();

};

#endif

countdown.cpp

#include "countdown.h"
#include <iostream>
using namespace std;

void countdown::vEntry()
{

	cout << "Please enter in the number of hours you require: ";
	cin >> tHours;

	/*while (!(cin >> tHours)) //Data Validation check. Display error message if data other than an integer is entered.
	{
		cin.clear();
		cin.ignore(100000000000000000, '\n');
		cout << "Not Valid Entry!\n\n";
		cout << "Please enter in the number of hours you require: ";
	}*/

	cout << "\nPlease enter in the number of minutes you require: ";
	cin >> tMinutes;

	while (!(cin >> tMinutes))
	{
		cin.clear();
		cin.ignore(100000000000000000, '\n');
		cout << "Not Valid Entry!\n\n";
		cout << "Please enter in the number of minutes you require: ";
	}
	
	cout << "\nPlease enter in the number of seconds you require: ";
	cin >> tSeconds;

	while (!(cin >> tSeconds))
	{
		cin.clear();
		cin.ignore(100000000000000000, '\n');
		cout << "Not Valid Entry!\n\n";
		cout << "Please enter in the number of seconds you require: ";
	}
}

void countdown::timecal()
{

	tTime[1] = (tHours * 60) * 60; //Calculation used to convert hours into minutes into seconds
	tTime[2] = tMinutes * 60; //Calculation used to convert minutes into seconds
	tTime[0] = tTime[1] + tTime[2] + tSeconds; //Calculation used to create the total number of seconds


	cout << "\nTotal time in seconds: ";
	cout << tTime[0];
	cout << "\n\nPlease press any key to start.\n\n";

	system("PAUSE");

	//return tTime[0];
}

void countdown::clock()
{
	
	cout << tClock;
	cout << "\n";

	//While loop used to compair the current clock with the result from the user, it adds one to the current clock until it is equal to it.
	//The code has been designed to dissplay the current number on the clock.
	while (tClock < tTime[0])
	{

		tClock++;
		cout << tClock;
		cout << "\n";

	}

	cout << "\n\nTotal time: ";
	cout << tClock;
	cout << "\n\nTime complete, lock is open\n\n";

	system("PAUSE");
}
1 Reply
Highlighted
Commander Lvl 2
Message 2 of 2

Re: Review my C++ project

You're a little more likely to get useful feedback if you can be more specific about the problems.

1. What specifically is the "stack error" or "corrupt" error you are getting? Which function is the problem in?

2. What specific validation problems are you having?

 

If you could state which operating system and compiler you are using, that might be helpful as well.

 

Please follow-up to let us know how you made out. For good karma, mark a reply as the answer if it helped!