uhmm??...

Pages: 12
so here is my program: (which works)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include<iostream>

using namespace 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
Last edited on
quick question and new to computer language...what is iostream?
from what i knew its the input/output thing
@linEmoguy
so here is my program: (which works)


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
Last edited on
ah, ok. thank you for clearing that up. I see now.
Vlad, he wishes to add data validation.

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 ).
Write a function that validates the time.
Last edited on
@Lynx Ok?..........
I dont know how xD
I see that the following code

1
2
		int adjusted_hour = ( a + c );
		int adjusted_hour2 = (24-adjusted_hour) % 24;


is duplicated many times. It means that you should rewrite your program in more effective way.:)
Ah, that is understandable :) thank you Lynx876
1
2
3
4
5
6
7
8
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! (:
Last edited on
@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.
Last edited on
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.
Last edited on
ok then
oh Lynx where do i squeeze in those codes u posted?
closed account (3qX21hU5)
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.
Last edited on
Think about 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.

http://www.cplusplus.com/doc/tutorial/functions2/
http://www.learncpp.com/cpp-tutorial/73-passing-arguments-by-reference/

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().
my apologies for taking so long to reply, i seem to be having troubles understanding it
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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//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();
}


To use 13 in the loop, I've used the decimal value of enter;
Ascii link: http://www.asciitable.com/
Last edited on
Pages: 12