Created
June 28, 2012 03:17
-
-
Save mikelopez/3008713 to your computer and use it in GitHub Desktop.
Sample loop demonstration assignment to calculate averages and commission rates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <cstdlib> | |
using namespace std; | |
int main() { | |
int totals; | |
double total_array[6]; | |
int grand_total = 0; | |
int loop_counter = 0; | |
/* Include days of week for representing */ | |
const char * const dow[] = {"MON", "TUE", "WED", "THRS", "FRI", "SAT", "SUN"}; | |
/* demonstration using for loop */ | |
for (int i = 0; i < 7; i++) { | |
cout << "#" << i << ") "; | |
cout << "Enter total for " << dow[i] << ": \n"; | |
cin >> totals; | |
total_array[i] = totals; | |
cout << "You entered: " << totals << "\n"; | |
grand_total += totals; | |
} | |
/* demonstration using while loop */ | |
cout << "\n\nWeekly sales: \n"; | |
while (loop_counter < 7) { | |
if (loop_counter == 7) { | |
cout << total_array[loop_counter]; | |
} else { | |
cout << total_array[loop_counter] << ", "; | |
} | |
loop_counter++; | |
} | |
cout << "\n\nTotal: " << grand_total << "\n"; | |
/* calculate the average */ | |
cout << "Average: " << (grand_total / 7) << "\n"; | |
/* calculat commision */ | |
if (grand_total > 99 && grand_total < 300) { | |
/* calculate grand_total by 3% */ | |
} | |
if (grand_total > 300 && grand_total < 500) { | |
/* calculate grand)total by 4% */ | |
} | |
if (grand_total > 500) { | |
/* calculate grand_total by 5% */ | |
} | |
cout << "\n\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment