help me

Write your question here.
case 'B' : cout << "\nThis is class b section " <<endl;
cout << "\nThis rential period consist 1 to 6 Days, 7 to 27 Days and 28 to 60 Days ";
cout << "\n1 to 6 Days = X, \n7 to 27 Days = Y, \n28 to 60 Days = Z ";
cout << "\nPlease select the period range carefully (X,Y,Z): ";
cin>> range;

if (range==X)
{
cout << "\nYou have enter the 1 to 6 Days range " <<endl;
cout << "\nPlease insert your rential period: ";
cin>>period;
New_amount = 27*period;
cout << "\nPROCESSING ...... PLEASE WAIT ";
cout << "\nThis is the amount you have to pay:RM " << New_amount;
}
My Question : I can't put my rential period at cin>>period;
It just straight to the cout
Can i know Why? and How?
And also i can't even got exact amount
Last edited on
What is the type of range and period variables?
the range and period are within 6 Days and i dont know how to put the variable's coding
Yes. But what are their types? (Int,string...)
int
Hello khairil27,

PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code.

It makes it easier to read your code and also easier to respond to your post.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.

I found the second link to be the most help.

Please post the whole code that can be compiled and run. Right now I can only guess at the missing pieces.

When I fixed the code to be able to compile and run I am not sure if what I did is correct.

Such as what should the value if "X" be? And where did this value come from?

In one test "X" had no value, so at the if condition "range" is being compared to either a garbage value for "X" or nothing.

In another test when I gave "range" and "X" the same value it worked.

It is always best to post the complete compilable code not just the part that you think is the problem. The real problem may start somewhere else.

Hope that helps,

Andy
Hello khairil27,

I did manage to get the program to run.

Note my questions in the output:

This is class b section

This rential period consist 1 to 6 Days, 7 to 27 Days and 28 to 60 Days
1 to 6 Days = X,
7 to 27 Days = Y,
28 to 60 Days = Z
Please select the period range carefully (X,Y,Z): x  // <--- You have no way of dealing with lower case letters.

You have enter the 1 to 6 Days range

Please insert your rental period: 6  // <--- How do I know what a "rental period" is and what to enter?

PROCESSING ...... PLEASE WAIT

This is the amount you have to pay:RM 162.00

 Press Enter to continue:



Andy
I didn't intended to stress the "bank" part. My point is that essentially just money related establishments are utilizing COBOL. In the event that somebody chooses to pursue that vocation way, they're probably going to wind up getting bolted into that area. What other forthcoming business will mind in the event that you have five years of experience keeping up a COBOL codebase? Individuals aren't taking those occupations since they understand that they'd go for broke without being satisfactorily redressed.

Where should individuals take in the abilities? Who will show youthful willing prospects COBOL on a centralized computer? Appears organizations are not intrigued to prepare individuals.

Inevitably it won't make any difference whether they're occupied with preparing hirees or not. In the long run there will be nobody who knows COBOL and doesn't as of now work in a bank. Their solitary decisions will be to either resign the codebase or prepare individuals themselves.

BANDAR TOGEL TERPERCAYA
https://www.mega4d.net
Hello Andy,

This is my whole code that can be compile and please help me to find the mistake. Thanks

#include <iostream>
#include <cmath>
using namespace std;
int main()

{

int period,New_amount,RM27,RM162,RM662,RM34,RM204,RM284,RM276,RM1136,range;
char choice,X,Y,Z,Q,W,E,R,T,U,P,M,N,O;

cout << "Class b = B, Class c = C, Class d = D" <<endl;
cout << "\nPlease choose one of the class (B,C,D): ";
cin>> choice;


switch (choice)
{

case 'B' : cout << "\nThis is class B section " <<endl;
cout << "\nThis rential period consist 1 to 6 Days, 7 to 27 Days and 28 to 60 Days ";
cout << "\n1 to 6 Days = X, \n7 to 27 Days = Y, \n28 to 60 Days = Z ";
cout << "\nPlease select the period range carefully (X,Y,Z): ";
cin>> range;

if (range == X)
{
cout << "\nYou have enter the 1 to 6 Days range " <<endl;
cout << "\nPlease insert your rential period: ";
cin >>period;
New_amount == (27*period);
cout << "\nPROCESSING ...... PLEASE WAIT ";
cout << "\nThis is the amount you have to pay:RM " << New_amount;
}

else if (range == Y)
{
cout << "\nYou have enter the 7 to 27 Days range " <<endl;
cout << "\n\t\t\t\t7 Days ---> RM162 " ;
cout << "\n\t\t\t\tAdditional 1 Days ---> +RM25 " ;
cout << "\nPlease insert your rential period : ";
cin >> period;
New_amount = (162+period);
cout << "\nThis is the amount you have to pay:RM " << New_amount ;
}

else if (range == Z)
{
cout << "\nYou have enter the 28 to 60 Days range " <<endl;
cout << "\n\t\t\t\t28 Days ---> RM662 " ;
cout << "\n\t\t\t\tAdditional 1 Days ---> +RM23 " ;
cout << "\nPlease insert your rential period : ";
cin >> period;
New_amount = (662+period);
cout << "\nThis is the amount you have to pay:RM " << New_amount ;
}

else
cout << " INVALID PERIODS ";
break;

case 'C' : cout << "\nThis is class C section " <<endl;
cout << "\nThis rential period consist 1 to 6 Days, 7 to 27 Days and 28 to 60 Days ";
cout << "\n1 to 6 Days = T, \n7 to 27 Days = U, \n28 to 60 Days = P ";
cout << "\nPlease select the period range carefully (T,U,P): ";
cin >> range;

if (range == T)
{
cout << "\nYou have enter the 1 to 6 Days range " <<endl;
cout << "\nPlease insert your rential period: ";
cin >> period;
New_amount = (RM34*period);
cout << "\nThis is the amount you have to pay:RM " << New_amount ;
}

else if (range == U)
{
cout << "\nYou have enter the 7 to 27 Days range " <<endl;
cout << "\n\t\t\t\t7 Days ---> RM204 " ;
cout << "\n\t\t\t\tAdditional 1 Days ---> +RM31 ";
cout << "\nPlease insert your rential period (Days): ";
cin >> period;
New_amount = (RM204+period);
cout << " This is the amount you have to pay:RM " << New_amount ;
}

else if (range == P)
{
cout << "\nYou have enter the 28 to 60 Days range " <<endl;
cout << "\n\t\t\t\t28 Days ---> RM284 " ;
cout << "\n\t\t\t\tAdditional 1 Days ---> +RM28 " ;
cout << "\nPlease insert your rential period (Days): ";
cin >> period;
New_amount = (RM284+period);
cout << "\nThis is the amount you have to pay:RM " << New_amount ;
}

else
cout << " INVALID PERIODS ";
break;

case 'D' : cout << "\nThis is class D section " <<endl;
cout << "\nThis rential period consist 1 to 6 Days, 7 to 27 Days and 28 to 60 Days ";
cout << "\n1 to 6 Days = M, \n7 to 27 Days = N, \n28 to 60 Days = O ";
cout << "\nPlease select the period range carefully (M,N,O): ";
cin >> range;

if (range == M)
{
cout << "\nOpsss! You have enter the 1 to 6 Days range " <<
"\nclass D cars cannot be rented less than 6 Days is displayed." <<endl;
cout << " SORRY ";
}

else if (range == N)
{
cout << "\nYou have enter the 7 to 27 Days range " ;
cout << "\n\t\t\t\t7 Days ---> RM276 " ;
cout << "\n\t\t\t\tAdditional 1 Days ---> +RM43 ";
cout << "\nPlease insert your rential period (Days): ";
cin >> period;
New_amount = (RM276+period);
cout << "\nThis is the amount you have to pay:RM " << New_amount ;
}

else if (range == O)
{
cout << "\nYou have enter the 28 to 60 Days range ";
cout << "\n\t\t\t\t28 Days ---> RM1136 " ;
cout << "\n\t\t\t\tAdditional 1 Days ---> +RM38 ";
cout << "\nPlease insert your rential period (Days): ";
cin >> period;
New_amount = (RM1136+period);
cout << "\nThis is the amount you have to pay:RM " << New_amount ;
}

else
cout << " INVALID PERIODS ";


default : cout << " INVALID CLASS ";
}

return 0;

}
Last edited on
Hello khairil27,

I have not had the time to dig into the program in depth, but one thing I do see is: if (range == X). You enter a value for "range", but "X" is a variable and only after I initialized this variable did it have a value and that would be "\0". So, the if statement is checking if "range", which equals "X", is equal to the variable "X", which is "\0", and the result is false.

Your if statements should be written as: if (range == 'X'). This way you are checking the value of "range" against the character "X" and not a variable with no value. Before you think about it or give it a try giving the variables like "X", "Y", "Z" etc will not work.

Last time

PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code.

It makes it easier to read your code and also easier to respond to your post.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.

I found the second link to be the most help.

If you do not understand just say so,

Just so you know the program did not compile on my system with out warnings and errors. Most errors had to do with variables being defined, but not initialized. Strange things can happen when you try to use an uninitialized variable.

I need to make some changes and test. I will let you know what I find.

Hope that helps,

Andy
Hello Andy,

Thank you for your advise. I will improve my posting in future and ease the way for you to help me with the coding.

Thank you soo much for helping me

:)
Hello khairil27,

Initial work lead me to this:
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
#include <iostream>
#include <cctype>  // <--- For std::tolower() and std::toupper().
//#include <cmath>  // <--- As of now I have not fould where this header file is needed. Maybe for the future?

using namespace std;  // <--- Best not to use.

int main()
{
	int period, New_amount{}, RM27{}, RM162{}, RM662{}, RM34{}, RM204{}, RM284{}, RM276{}, RM1136{};
	char choice{ 'B' }, range{};  // , X{}, Y{}, Z{}, Q{}, W{}, E{}, R{}, T{}, U{}, P{}, M{}, N{}, O{};  // <--- Not used or needed. Moved "range" here.

	cout << "Class b = B, Class c = C, Class d = D" << endl;  // <--- Have no idea what this means. You are working "case"s not classes.
	cout << "\nPlease choose one of the class (B,C,D): ";
	//cin >> choice;  // <--- Did this to speed up testing.
	choice = std::toupper(choice);  // <--- One option.

	switch (std::toupper(choice))  // <--- Another option.
	{

		case 'B':
			cout << "\nThis is class B section " << endl;
			cout << "\nThis rential period consist 1 to 6 Days, 7 to 27 Days and 28 to 60 Days ";
			cout << "\n1 to 6 Days = X, \n7 to 27 Days = Y, \n28 to 60 Days = Z ";
			cout << "\nPlease select the period range carefully (X,Y,Z): ";
			cin >> range;

			if (std::toupper(range) == 'X')
			{
				cout << "\nYou have enter the 1 to 6 Days range " << endl;
				cout << "\nPlease insert your rential period: ";  // <--- Still have no idea what should be entered here.
				cin >> period;
				New_amount = (27 * period);  // <--- Changed from "==" to "=". You need to set "New_amount" equal to the calculation not chech if it is equal to.
				cout << "\nPROCESSING ...... PLEASE WAIT ";
				cout << "\nThis is the amount you have to pay:RM " << New_amount;
			}

Notice that I put a comment on the single letter variables. First do not ue capital letters. it makes me think that it is defined as a constant. Second a more descriptive name would help. Right now all these variables are not used.

When I first compiled the program I received many error messages about using uninitialized variables. I did not take the time to figure out which variable(s) needed to be initialized I just did them all. The empty {}s initialize "int"s to zero and "char"s to "\0" "doubles would be "0.0". Strings, vectors, lists and other containers are a bit different as they are empty when they are defined and need no initialization. The other thing about the {}s is that you can put something inside to initialize the variable. What and how depends on the variable type. See the example for "choice".

Initializing variables is about a 50/50 choice. Sometimes you do not have to. My personal choice it to define and initialize a variable so that you have the peace of mind that it holds a known value and not garbage, so do not have to worry.

Do not get to excited about this code as I have had to make some changes/additions, so the next bit of code will look very different. Working on that now.

While I am working maybe you could explain all the variables that begin with "RM..." and all the single letter variables. What are they used for and what do they mean?

Hope that helps for now,

Andy
Hello khairil27,

As I progress this is what I have so far:
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
#include <iostream>
#include <cctype>  // <--- For std::tolower() and std::toupper().
//#include <cmath>  // <--- As of now I have not fould where this header file is needed. Maybe for the future?

//using namespace std;  // <--- Best not to use.

int main()
{
	constexpr int MAGIC_NUMBER1{ 27 };
	constexpr int MAGIC_NUMBER2{ 162 };
	constexpr int MAGIC_NUMBER3{ 662 };

	int period, New_amount{}, RM27{}, RM162{ 162 }, RM662{}, RM34{}, RM204{}, RM284{}, RM276{}, RM1136{};
	char choice, range{};  // , X{}, Y{}, Z{}, Q{}, W{}, E{}, R{}, T{}, U{}, P{}, M{}, N{}, O{};  // <--- Not used or needed. Moved "range" here.

	std::cout << "\n Class b = B, Class c = C, Class d = D" << std::endl;  // <--- Have no idea what this means. You are working "case"s not classes.
	std::cout << "\n Please choose one of the class (B,C,D): ";
	//std::cin >> choice;
	choice = 'B';
	choice = std::toupper(choice);  // <--- One option.

	switch (std::toupper(choice))  // <--- Another option.
	{

		case 'B':
			std::cout << "\n This is class B section " << std::endl;  // <--- OK for testing, but not needed.
			std::cout << "\n This rential period consist 1 to 6 Days, 7 to 27 Days and 28 to 60 Days ";
			std::cout << "\n X = 1 to 6 Days\n Y = 7 to 27 Days\n Z = 28 to 60 Days";
			std::cout << "\n Please select the period range carefully (X,Y,Z): ";

			//std::cout << "\nThis is class B section " << std::endl;
			//std::cout << "\nThis rential period consist 1 to 6 Days, 7 to 27 Days and 28 to 60 Days ";
			//std::cout << "\n1 to 6 Days = X, \n7 to 27 Days = Y, \n28 to 60 Days = Z ";
			//std::cout << "\nPlease select the period range carefully (X,Y,Z): ";
			std::cin >> range;
			range = std::toupper(range);  // <--- Here I think this is the best usage.

			if (range == 'X')
			{
				std::cout << "\nYou have enter the 1 to 6 Days range " << std::endl;
				std::cout << "\nPlease insert your rential period: ";  // <--- Still have no idea what should be entered here.
				std::cin >> period;
				New_amount = (MAGIC_NUMBER1 * period);  // <--- Changed from "==" to "=". You need to set "New_amount" equal to the calculation not chech if it is equal to.
				std::cout << "\nPROCESSING ...... PLEASE WAIT ";  // <--- This looks nice, but the processing time is so short that it does not mean much.
				std::cout << "\nThis is the amount you have to pay:RM " << New_amount;
				//break;  // <--- You could put break a statement here and in the else if statements. In a do/while loop it would leave the loop.
			}

			else if (range == 'Y')
			{
				std::cout << "\n You have enter the 7 to 27 Days range " << std::endl;
				std::cout << "\n 7 Days ---> " << RM162;
				std::cout << "\n Additional 1 Days ---> + RM25 \n";
				std::cout << "\n Please insert your rential period : ";
				std::cin >> period;
				New_amount = (MAGIC_NUMBER2 + period);
				std::cout << "\n This is the amount you have to pay:RM " << New_amount;
			}

			else if (range == 'Z')
			{
				std::cout << "\n You have enter the 28 to 60 Days range " << std::endl;
				std::cout << "\n 28 Days ---> RM662 ";
				std::cout << "\n Additional 1 Days ---> +RM23 ";
				std::cout << "\n Please insert your rential period : ";
				std::cin >> period;
				New_amount = (MAGIC_NUMBER3 + period);
				std::cout << "\n This is the amount you have to pay:RM " << New_amount;
			}

			else
				std::cout << " INVALID PERIODS ";  // <--- If you reach here it would be nice to start over and be able to enter a correct range. A do/while loop would work.
			break;

		

I have only worked with case "B" so far, but the concept will be the same for the others.

The first three lines in "main lines 9 -11 are the more accepted way of replacing the magic numbers inside you if statements. I suggest yo change the "MAGIC_NUMBER?" to a name that better describes what it is used for. Putting this here at the top makes it easier to make changes in the future. I am also leaning towards making the "RM???" variables constants also because what I see is that these variables do not change and they should be given a value to be used in the program.

I changed the menu around. See what you think. Either way works. Over time and experience I have learned what makes a better format for a menu. I have also learned that some things in programming have an unwritten rule about how to do them. You will learn this in time.

In the else if statements for "Y" and "Z" I have this feeling that the calculation for "New_ammount" is wrong. It feels like something is missing.

For "Y" if up to six days is worth 162 than 12 days would be worth 324, so 24 days would be worth 648 and then you might have up to three more days to deal with.

You taking a base amount and adding something to it does not seem right.

Hope this helps,

Andy
Hello khairil27,

Sorry I meant to put this in the last message:

 Class b = B, Class c = C, Class d = D

 Please choose one of the class (B,C,D):
 This is class B section

 This rental period consist 1 to 6 Days, 7 to 27 Days and 28 to 60 Days
 X = 1 to 6 Days
 Y = 7 to 27 Days
 Z = 28 to 60 Days
 Please select the period range carefully (X,Y,Z): y

 You have enter the 7 to 27 Days range

 7 Days ---> RM162  // <--- What is the use of "RM162" here? Should "RM162" be output as a variable, which at this point has no value except zero, or does it have another use?
 Additional 1 Days ---> + RM25  // <--- Again the "RM25" does not make any sense here to me.

 Please insert your rental period : 30  // <--- If I enter "30" here...

 This is the amount you have to pay:RM 192  // <--- The calculation here does not seem right.

 Press Enter to continue: 


Note the comments.

Note: Just a small thing "rential" is spelled "rental". This could be a language thing.

Andy
Topic archived. No new replies allowed.