Sythe.Org Forums     Register     FAQ     Members List     Calendar     Mark Forums Read    
 
Sythe.Org Forums  
   Runescape Gold

Sythe.org — A Virtual Goods Trading Hub

Make real cash! buying and selling in-game items.

We have a no-scam policy.

You can make thousands playing your favourite games here at Sythe.org.

Just sign up an account and follow the rules!


Take me to

Runescape Markets

Other Game Markets

Support Center

Register an Account

Close
[NEWB FRIENDLY] Simple Hours to Minutes Converter.
Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 09-14-2009, 03:54 AM
Active Member
 
Join Date: Mar 2009
Posts: 238
Default [NEWB FRIENDLY] Simple Hours to Minutes Converter.

Feel free to experiment with the code or ask any questions:
Code:
#include <iostream>
#include <cstring>
#include <windows.h>
#include <fstream>
using namespace std;

int hrsEnt () //function
{
    char hrs[10]; 
    int min;
    char conf[10];
    int y = 0;
    static bool exitTxt = false;

        cout << "Enter hours:" << endl; // prints out a line that asks for the user to enter a number it the program
     if (!exitTxt) //want it to show once so the user doesn't get annoyed by this line getting spammed
     {
     cout << "Please type exit to safely quit this program" << endl; //this is the line we don't want to to be spammed
     exitTxt = true;
     }   
     cin.getline ( hrs, 10 ); //user's input = hrs


        if ( strcmp( hrs, "0" ) == 0) //if user writes the value 0
       {
             cout << "Obviously, there is 0 minutes in 0 hours NOOB\n" << "Try putting a number greater than 0" << endl; // will generate this line
             hrsEnt (); //will restart this function.. 
       } 



        else if ( strcmp( hrs, "exit" ) == 0) //if user inputs the word "exit"
        {
              cout << "Are you sure you want to exit? (yes or no)" << endl; //asks for confirmation
              cin.getline ( conf, 10 ); //getting the user input into conf
        
        if ( strcmp( conf, "yes" ) == 0 || strcmp( conf, "Yes" ) == 0 || strcmp( conf, "YES" ) == 0 || strcmp( conf, "exit")) //if user writes "yes"
	    {
               int x = 5;
               while ( x > 0) //displays "Program exiting in 5, 4 ,3 ,2 ,1"
               {
               cout << "Exiting program in " << x << endl;
               x--;
               Sleep(500);
               }
               ofstream a_file ( "Results.txt", ios::app ); //writes in the results.txt file "end of session"
               a_file << "End of session\n" << "-----------------------------------\n" << "\n" << endl;
               a_file.close();
               return 0; //exit program with no erorrs
		 }
	     if ( strcmp( conf, "no" ) == 0 || strcmp( conf, "No" ) == 0 || strcmp( conf, "NO" ) == 0) //if user writes "no"
		 {
			   hrsEnt (); //restart program
		 }
	}



	else if ( strcmp( hrs, "1" ) == 0) //of user writes 1 
		{
            
		 cout << "There is 60 minutes in 1 hour" << endl; //generate this line only IF user writes 1
		 hrsEnt (); //restart program
    
	    }


    else
     {
         int hrsInt = 0;
         static bool shown = false;
         static bool intro = false;
         hrsInt = atoi(hrs); //converting the string into an integer so it could manipulated
      
         min = (hrsInt * 60); //multiplies whatever the user inputed by 60 so it gives him the result
         cout << "There is " << min << " minutes in " << hrs << " hours" << endl; // here it prints out the result
         ofstream a_file ( "Results.txt", ios::app ); //create Results.txt file to write results into

         if (!intro)
         {
         a_file << "Your results saved from Hours to Minutes Converter:" << endl; //telling the program to only write this line once in a session so it doesn't spam the output
         intro = true;
         }
         a_file << "There is " << min << " minutes in " << hrs << " hours" << endl; //prints out the result in a text file
         a_file.close(); //closes the file editing session
         if (!shown) //will notify the user ONCE that the results will be all saved to Results.txt
         {
         cout << "All results has been saved to Results.txt" << endl; //this what the user will see as a confirmation
         shown = true;
         }      
         hrsEnt (); //restart the fucntion
         
     }
   
    
}


int main () //main function
{
          hrsEnt (); //exceute the function we coded
}

Last edited by prorathack1 : 09-14-2009 at 03:54 AM.
Reply With Quote
  #2  
Old 09-14-2009, 08:46 AM
Swan's Avatar
When They Cry...
Ex-Moderator
 
Join Date: Jan 2007
Location: Japan
Posts: 4,404
Default Re: [NEWB FRIENDLY] Simple Hours to Minutes Converter.

You're making it way more complex than it needs to be, and it is very messy. In terms of standard code, this is a lot tidier, and hence a lot easier to read. Code that is easier to read is what I'd call "newb friendly".

Code:
#include "stdio.h"
#include "string.h"
#include "ctype.h"

// Declare strtolower(char* input) function.
// For those who are unfamiliar with C++ function declarations,
// the actual function is below the main function.
void strtolower(char* input);

int main(int argc, char** argv)
{
    // While this remains true ...
    bool running = true;
    // ... The program will continue looping.
    while(running)
    {
        printf("Enter conversion:\n\t %s \n\t %s \n\t %s \n\t %s \n\t %s \n\t %s \n---\n\t %s \nChoice: ",
            "1. Seconds to minutes.",
            "2. Seconds to hours.",
            "3. Minutes to seconds.",
            "4. Minutes to hours",
            "5. Hours to seconds.",
            "6. Hours to minutes.",
            "0. Exit.");

        // Get the user's choice.
        int choice = 0;
        scanf("%i", &choice);

        // Declare input variables for seconds, minutes and hours.
        int sec = 0, min = 0, hr = 0;

        // Act upon user's choice conversion.
        switch(choice) {
            case 1:
                printf("Enter amount of seconds: ");
                scanf("%i", &sec);
                printf("There is %i minutes in %i seconds.", (sec / 60), sec);
                break;
            case 2:
                printf("Enter amount of seconds: ");
                scanf("%i", &sec);
                printf("There is %i hours in %i seconds.", (sec / 3600), sec);
                break;
            case 3:
                printf("Enter amount of minutes: ");
                scanf("%i", &min);
                printf("There is %i seconds in %i minutes.", (min * 60), min);
                break;
            case 4:
                printf("Enter amount of minutes: ");
                scanf("%i", &min);
                printf("There is %i hours in %i minutes.", (min / 60), min);
                break;
            case 5:
                printf("Enter amount of hours: ");
                scanf("%i", &hr);
                printf("There is %i seconds in %i hours.", (hr * 3600), hr);
                break;
            case 6:
                printf("Enter amount of hours: ");
                scanf("%i", &hr);
                printf("There is %i minutes in %i hours.", (hr * 60), hr);
                break;
            case 0:
                printf("Exiting...");
                return 0;
            default:
                printf("Please enter a valid choice.");
                break;
        }

        // Loop is used to ensure the program receives appropriate input string.
        for(;;)
        {
            // Ask for and scan input.
            printf("\nPerform another conversion? [yes/no]: ");
            char conversion[80];
            scanf("%s", &conversion);

            // Convert to lowercase.
            strtolower(conversion);

            // Note: strcmp(const char*, const char*)
            //      returns as 0 (false) for a match, and 1 (true) otherwise.
            // Check to see if the user wants to exit the program.
            if(!strcmp("no", conversion))
            {
                running = false;
            }
            else if(strcmp("yes", conversion))
            {   // Note: This is checking whether or not the string is NOT "yes"
                //      and giving an error if so.
                printf("Please enter 'yes' or 'no'.\n");
                continue;
            }

            break;
        }
    }

    return 0;
}

// Function strtolower(char* input)
//      Converts the input string to lowercase.
void strtolower(char* input)
{
    int i = 0;
    while(input[i])
        input[i++] = tolower(input[i]);
}
__________________
Quote:
[14:54:13] <&Filefragg> x9 is made of 5 glow in the dark gorilla dildos vibrating in unison.
[14:54:19] <%TDD> hot
[14:54:22] <+Aoi> Win
[14:54:23] <x9> I TOLD YOU NOT TO TELL ANYONE, DAMNIT

Last edited by Swan : 09-14-2009 at 08:53 AM.
Reply With Quote
  #3  
Old 09-14-2009, 03:03 PM
d great one's Avatar
Apprentice
 
Join Date: Nov 2007
Posts: 930
Send a message via MSN to d great one Send a message via Yahoo to d great one
Default Re: [NEWB FRIENDLY] Simple Hours to Minutes Converter.

Correct me if I am wrong, but isn't it a little long for a simple hours to minute converter?

You could do like

Enter hours:
scan hours
result = hours * 60;
print result

Isn't it?
__________________
SCAMMERS ARE LOSERS. DO NOT BE ONE OF THEM
==========================
New: Buying all account upgrades + 4 vouches
==========================
I CAN MM FOR YOU - MM THREAD + MM VOUCHES || vouch(es) on this thread: 10
==========================
MY MSN: [email protected]
==========================
NOW SELLING RSGP || vouch(es) on this thread: 30
==========================
Account Shop || vouch(es) on this thread: 1
Lost thread: My buying + vouches thread || vouch(es) on this thread: 82
Reply With Quote
  #4  
Old 09-15-2009, 09:10 AM
Swan's Avatar
When They Cry...
Ex-Moderator
 
Join Date: Jan 2007
Location: Japan
Posts: 4,404
Default Re: [NEWB FRIENDLY] Simple Hours to Minutes Converter.

Quote:
Originally Posted by d great one View Post
Correct me if I am wrong, but isn't it a little long for a simple hours to minute converter?

You could do like

Enter hours:
scan hours
result = hours * 60;
print result

Isn't it?
My version converts between hours, minutes and seconds based on the user's choice. His uses all of this unneeded strcmp() crap and so on.
__________________
Quote:
[14:54:13] <&Filefragg> x9 is made of 5 glow in the dark gorilla dildos vibrating in unison.
[14:54:19] <%TDD> hot
[14:54:22] <+Aoi> Win
[14:54:23] <x9> I TOLD YOU NOT TO TELL ANYONE, DAMNIT
Reply With Quote
  #5  
Old 09-15-2009, 03:01 PM
d great one's Avatar
Apprentice
 
Join Date: Nov 2007
Posts: 930
Send a message via MSN to d great one Send a message via Yahoo to d great one
Default Re: [NEWB FRIENDLY] Simple Hours to Minutes Converter.

I see. I didn't want to check his script because it is too long, and I trusted your judgment that his is a bit messy. And I don't like reading comments.
And I can see clearly now why you said his script is messy.

But we could give him a little clap for beginners.
__________________
SCAMMERS ARE LOSERS. DO NOT BE ONE OF THEM
==========================
New: Buying all account upgrades + 4 vouches
==========================
I CAN MM FOR YOU - MM THREAD + MM VOUCHES || vouch(es) on this thread: 10
==========================
MY MSN: [email protected]
==========================
NOW SELLING RSGP || vouch(es) on this thread: 30
==========================
Account Shop || vouch(es) on this thread: 1
Lost thread: My buying + vouches thread || vouch(es) on this thread: 82
Reply With Quote
  #6  
Old 09-15-2009, 11:11 PM
Member
 
Join Date: Dec 2008
Posts: 91
Default Re: [NEWB FRIENDLY] Simple Hours to Minutes Converter.

http://paste.upinthisbit.ch/6d96e2d3
Reply With Quote
  #7  
Old 10-18-2009, 12:32 AM
Member
 
Join Date: Dec 2008
Posts: 91
Default Re: [NEWB FRIENDLY] Simple Hours to Minutes Converter.

http://paste.upinthisbit.ch/a0696939 was bored
Reply With Quote
Reply



Cheap RS Gold Store  Runescape Gold

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

All times are GMT +1. The time now is 08:34 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.6.1