Announcements | Last Post | |
---|---|---|
![]() |
SoC Curricula | 09/30/2017 01:08PM |
![]() |
Demarcation or scoping of examinations and assessment | 02/13/2017 07:59AM |
![]() |
School of Computing Short Learning Programmes | 11/24/2014 08:37AM |
![]() |
Unisa contact information | 07/28/2011 01:28PM |
Study Guide Activities January 10, 2009 05:30PM |
Registered: 10 years ago Posts: 13 Rating: 0 |
Re: Study Guide Activities January 10, 2009 11:26PM |
Registered: 11 years ago Posts: 21 Rating: 0 |
Re: Study Guide Activities January 10, 2009 11:28PM |
Registered: 11 years ago Posts: 21 Rating: 0 |
Re: Study Guide Activities January 11, 2009 02:01PM |
Registered: 10 years ago Posts: 13 Rating: 0 |
Study Guide Activities - Lesson 4.b January 11, 2009 02:44PM |
Registered: 10 years ago Posts: 13 Rating: 0 |
Re: Study Guide Activities January 11, 2009 09:01PM |
Registered: 11 years ago Posts: 21 Rating: 0 |
January 12, 2009 06:31PM |
Registered: 12 years ago Posts: 472 Rating: 0 |
Re: Study Guide Activities January 12, 2009 09:07PM |
Registered: 11 years ago Posts: 21 Rating: 0 |
Re: Study Guide Activities January 13, 2009 09:11AM |
Registered: 10 years ago Posts: 13 Rating: 0 |
Re: Study Guide Activities - Lesson 4.b January 13, 2009 10:48PM |
Registered: 10 years ago Posts: 5 Rating: 0 |
Re: Study Guide Activities January 15, 2009 09:09AM |
Registered: 10 years ago Posts: 3 Rating: 0 |
January 21, 2009 03:00PM |
Registered: 14 years ago Posts: 560 Rating: 2 |
Re: Study Guide Activities January 22, 2009 11:37AM |
Registered: 14 years ago Posts: 9 Rating: 0 |
Re: Study Guide Activities January 22, 2009 09:32PM |
Registered: 10 years ago Posts: 94 Rating: 0 |
Re: Study Guide Activities January 27, 2009 11:17AM |
Registered: 14 years ago Posts: 9 Rating: 0 |
February 04, 2009 01:54PM |
Registered: 14 years ago Posts: 1,424 Rating: 0 |
Quote
mikek
When you do not explicitly assigned a value to a variable in C++ , that variable will be assigned a kind of random value (not really random) from the heap.
That is why you see a strange value on that variable (in your case the integer answer.).
Re: Study Guide Activities February 09, 2009 09:23AM |
Registered: 10 years ago Posts: 1 Rating: 0 |
Re: Study Guide Activities February 16, 2009 11:34PM |
Registered: 10 years ago Posts: 13 Rating: 0 |
Study Guide Activities - Lesson 12 March 02, 2009 07:20PM |
Registered: 10 years ago Posts: 13 Rating: 0 |
Language: C++//Lesson Notes //Lesson 12 - Activity 12a //Write a program that reads in the starting and finishing times //of a waitron and calculates the wage for the work done. //Constants are: // R32.50 per hour between 1 - 6 // R44.00 per hour between 6 -12 #include <iostream> using namespace std; int main() { //declare variables const float DAY_RATE = 32.50; //holds the day rate const float NIGHT_RATE = 44.00; //holds the night rate int dayRange, nightRange; //hold the amount of hours float amount = 0.00; //holds the amount to be paid int startTime, endTime; //holds the times //ask and store for user start time cout << "Wage Calculation" << endl; cout << "================" << endl; cout << "Starting time: "; cin >> startTime; //ask and store for user end time cout << "Finishing time: "; cin >> endTime; //calculate the amount that needs to be paid dayRange = 6 - startTime; nightRange = endTime - 6; if (dayRange !=0) { amount += dayRange * DAY_RATE; } if (nightRange !=0) { amount += nightRange * NIGHT_RATE; } //display the result cout.setf(ios::fixed); cout.precision(2); cout << endl; cout << "The payment is R " << amount << endl; //end the program return 0;
March 03, 2009 09:06AM |
Registered: 14 years ago Posts: 560 Rating: 2 |
Wage calculation ================ Starting time: 7 Finishing time: 12 The payment is R 220.00 Press any key to continue . . .Output from your program:
Wage Calculation ================ Starting time: 7 Finishing time: 12 The payment is R 231.50 Press any key to continue . . .The reason for the difference is that both your if statements will be evaluated whilst only one of the (nested) if statements in the original program in the Activity will be evaluated; ie.
if (start < 6)OR
else wage = (finish - start) * EVENING_RATE;Debugging your program showed that when the compiler evaluates the first if statement the variable amount = -32.50
But since the variable 'amount' has a value = -32.50 ( calculated previously ) the above statement evaluates toLanguage: C++amount += nightRange * NIGHT_RATE;
The lesson does not state why one would use nested if statements, unless there are three or more conditions that need to be evaluated to either true or false. (Is this correct?)It depends on the problem at hand and how you want to implement it.
Re: Study Guide Activities March 03, 2009 09:40AM |
Registered: 10 years ago Posts: 13 Rating: 0 |
March 03, 2009 09:53AM |
Registered: 14 years ago Posts: 560 Rating: 2 |
Re: Study Guide Activities March 05, 2009 09:05PM |
Registered: 10 years ago Posts: 13 Rating: 0 |
March 06, 2009 08:39AM |
Registered: 14 years ago Posts: 560 Rating: 2 |
Re: Study Guide Activities March 11, 2009 11:02AM |
Registered: 10 years ago Posts: 2 Rating: 0 |
March 11, 2009 11:18AM |
Registered: 14 years ago Posts: 560 Rating: 2 |
Language: C++//Calculates the number of digits in a number #include <iostream> using namespace std; int main( ) { int number, num, count; //Prompt the user for a number cout << "Enter an integer: "; cin >> number; num = number; //Determine the number of digits in the number count = 0; do { count++; num /= 10; } while (num != 0); cout << number << " contains " << count << " digit(s)" << endl; return 0; }