#include<iostream>
usingnamespace std;
int a,b,c;
char ans;
int main()
{
do
{
cout<<"Enter number of hours (in 24H Format):";
cin>>a;
cout<<"Enter number of minutes:";
cin>>b;
cout<<"Select time zone (-12 to +12):";
cin>>c;
if (c == -12)
{
int adjusted_hour = ( a + c );
int adjusted_hour2 = (24-adjusted_hour) % 24;
cout<<"International date line west UTC -12 : "<<adjusted_hour2<<":"<<b<<endl;
}
if (c== -11)
{int adjusted_hour = ( a + c );
int adjusted_hour2 = (24-adjusted_hour) % 24;
cout<<"Samoa Standard Time UTC -11 : "<<adjusted_hour2<<":"<<b<<endl;}
if (c== -10)
{
int adjusted_hour = ( a + c );
int adjusted_hour2 = (24-adjusted_hour) % 24;
cout<<"Hawaiian Standard Time UTC -10 : "<<adjusted_hour2<<":"<<b<<endl;
}
if (c== -9)
{
int adjusted_hour = ( a + c );
int adjusted_hour2 = (24-adjusted_hour) % 24;
cout<<"Alaska Standard Time UTC -9 : "<<adjusted_hour2<<":"<<b<<endl;
}
if (c== -8)
{
int adjusted_hour = ( a + c );
int adjusted_hour2 = (24-adjusted_hour) % 24;
cout<<"Pacific Standard Time UTC -8 : "<<adjusted_hour2<<":"<<b<<endl;
}
if (c== -7)
{
int adjusted_hour = ( a + c );
int adjusted_hour2 = (24-adjusted_hour) % 24;
cout<<"Mountain Standard Time UTC -7 : "<<adjusted_hour<<":"<<b<<endl;
}
if (c== -6)
{
int adjusted_hour = ( a + c );
int adjusted_hour2 = (24-adjusted_hour) % 24;
cout<<"Central Standard Time UTC -6 : "<<adjusted_hour2<<":"<<b<<endl;
}
if (c== -5)
{
int adjusted_hour = ( a + c );
int adjusted_hour2 = (24-adjusted_hour) % 24;
cout<<"Eastern Standard Time UTC -5 : "<<adjusted_hour2<<":"<<b<<endl;
}
if (c== -4)
{
int adjusted_hour = ( a + c );
int adjusted_hour2 = (24-adjusted_hour) % 24;
cout<<"Atlantic Standard Time UTC -4 : "<<adjusted_hour2<<":"<<b<<endl;
}
if (c== -3)
{
int adjusted_hour = ( a + c );
int adjusted_hour2 = (24-adjusted_hour) % 24;
cout<<"Brazil Standard Time UTC -3 : "<<adjusted_hour2<<":"<<b<<endl;
}
if (c== -2)
{
int adjusted_hour = ( a + c );
int adjusted_hour2 = (24-adjusted_hour) % 24;
cout<<"Greenland Eastern Standard Time UTC -2 : "<<adjusted_hour2<<":"<<b<<endl;
}
if (c== -1)
{int adjusted_hour = ( a + c );
int adjusted_hour2 = (24-adjusted_hour) % 24;
cout<<"Azores Time UTC -1 : "<<adjusted_hour2<<":"<<b<<endl;
}
if (c== 0)
{
int adjusted_hour = (a + c ) % 24;
cout<<"Greenwich Mean Time UTC 0 : "<<adjusted_hour<<":"<<b<<endl;
}
if (c== +1)
{
int adjusted_hour = (a + c ) % 24;
cout<<"Central Europe time UTC +1 : "<<adjusted_hour<<":"<<b<<endl;
}
if (c== +2)
{
int adjusted_hour = (a + c ) % 24;
cout<<"Eastern Europe time UTC +2 : "<<adjusted_hour<<":"<<b<<endl;
}
if (c== +3)
{
int adjusted_hour = (a + c) % 24;
cout<<"Moscow Time UTC +3 : "<<adjusted_hour<<":"<<b<<endl;
}
if (c== +4)
{
int adjusted_hour = (a + c) % 24;
cout<<"Gulf Standard Time UTC +4 : "<<adjusted_hour<<":"<<b<<endl;
}
if (c== +5)
{
int adjusted_hour = (a + c) % 24;
cout<<"Pakistan Time UTC +5 : "<<adjusted_hour<<":"<<b<<endl;
}
if (c== +6)
{
int adjusted_hour = (a + c) % 24;
cout<<"Bangladesh Time UTC +6 : "<<adjusted_hour<<":"<<b<<endl;
}
if (c== +7)
{
int adjusted_hour = (a + c) % 24;
cout<<"Java Time UTC +7 : "<<adjusted_hour<<":"<<b<<endl;
}
if (c== +8)
{
int adjusted_hour = (a + c) % 24;
cout<<"China Coast Time UTC +8 : "<<adjusted_hour<<":"<<b<<endl;
}
if (c== +9)
{
int adjusted_hour = (a + c) % 24;
cout<<"Japan Standard Time UTC +9 : "<<adjusted_hour<<":"<<b<<endl;
}
if (c== +10)
{
int adjusted_hour = (a + c) % 24;
cout<<"Guam Standard Time UTC +10 : "<<adjusted_hour<<":"<<b<<endl;
}
if (c== +11)
{
int adjusted_hour = (a + c) % 24;
cout<<"Solomon Islands time UTC +11 : "<<adjusted_hour<<":"<<b<<endl;
}
if (c== +12)
{
int adjusted_hour = (a + c) % 24;
cout<<"New Zealand Standard time UTC +12 : "<<adjusted_hour<<":"<<b<<endl;
}
cout<< "Do you want to do it again (Y/N)?";
cin >> ans;
system("cls");//system() danger???? lawl really?
}
while (ans == 'y'|| ans == 'Y' && ans != 'N' || ans != 'n');
cin.get();
return 0;
}
now im trying to make an incorrect input or something like that (and if possible) when you enter the time that is not supposed to be entered and it will be wrong and be asked to try again
So you have a program that works and now you are going to change it such a way that it will not work.:)
Do I have correctly understood you? If so I I could be useful!:)
@vlad from moscow
no thats not it:
example, what if the person puts in the time that is over 24 cuz its in 24 h format, that would make the total wrong
linEmoguy, try something like the following. I wont give you the code though (: lol
-Create a loop( do-while, so it's run before being checked ), which will not exit until until the data entered is correct.
-Within this loop, call a function to get the data from the user. (Just to keep the code clean. And you can use this function again if you need more data entry later on ).
do
{
if( collectData() )
break;
else
//output error message here. will output this until data is correct.
}while( true ); //infinite loop, until 'break;'
1 2 3 4 5 6 7 8 9 10 11
//collect data.cpp
bool collectData()
{
//get data here.
//check data.
//if the data is a correct format, return true
//else, return false, which will re-run this function.
}
Edit:
As Vlad has pointed out above. If you need to keep writing the same code, over and over, this code should be in a function of it's own. Then all you have to do is call a function! (:
@vlad of moscow
yea long,
but somehow when i try to make that part short it gives me a negative number, and the wrong answer
i just like making codes longer, lol, im trying to figure out how to make it short, anyways im a slow thinker, so it may take a long time, i hope not though.
You shouldn't try to make your code longer! The most amazing code, is code that's really short but can do more than it looks! Programming is always about efficiency! (:
And, I've practically gave you the answer! lol. You just have to replace comments with your code.
You don't you rewrite your whole program to be more efficient :). The same program could be done in under 50 lines, which is what Lynx is helping you with. He is giving you a basic template of how it should look.
If you don't know about functions have a look at the tutorial here on the website it should explain a lot of it.
Your data entry will go in the new function, collectData().
Then you're going to want the loop where data entry currently takes place, right?
But! Before attempting this, you may want to have a read through the two following sites, as you need to change more than one variable within the function and not return just one variable.
You're going to want to pass the variables by reference, meaning when there's a change in the function, this change is mirrored in the function that called the current function.
i.e.
main() calls dataCollection().
dataCollection() changes a variable.
This variable has also changed in main().
I just wrote this quickly, hopefully it will help you understand functions a little better. When I first looked at your code, in the first post, I thought I saw some functions in there. Sorry about that! lol.
//Console input/output
#include <iostream>
//Include this for _getch() to catch the key press. Lines 26 & 43.
#include <conio.h>
//Function prototype. Just a copy of the function.
void testFunction();
//The type is void, because the function will not be retruning anything.
int main()
{
//Create a char to catch the key pres. Init to NULL.
char key = '\0';
do
{
//While the key pressed is not enter, keep calling the test function.
testFunction();
std::cout << "You are in the 'main()' function.\n";
std::cout << "Press [ENTER] to exit, or any other key to keep looping.\n\n";
//Key the key pressed by the user.
key = _getch();
}while( key != 13 );
//13 is ascii for the key [ENTER].
//There's a link below.
std::cout << "You pressed [ENTER] in the main function\n";
return 0;
}
void testFunction()
{
std::cout << "You are now in the test function.\n";
std::cout << "Press {ANY} key to return to main.\n\n";
//Don't need to compare this key press with anything. So no assingment here.
_getch();
}