
please wait
"Write a program that asks the user for a positive integer. The program should use a loop to get the sum of all integers from 1 up to the number enetered. For example if the user enters 50, the loop will find hte sum of 1, 2, 3, 4, ....., 50. *Input validation* Do not accept a negative starting number." #include <iostream> #include <iomanip> using namespace std; int main() { int num, sum, days; // Initiate the counter //Get integer cout << "Enter a positive number "; cin >> days; cout << "\nNumber Number Summed\n"; cout << "----------------------------\n"; for (int i = 0; i < days; days--) cout << days << "\t\t" << (sum+=days) << endl; system ("pause"); return 0; } |
"Write a program that calculates how much a person would earn over a period of time if his/her salary is 1 penny for the first day and 2 pennies for the second day, and continues to double each day. The program should ask the user for the number of days. Display a table showing how much the salary was for each day and then show teh total pay at teh end of the period. The output should be displayed in a dollar ammount, not the number of pennies. *Input vaildation* Do not accept a number less than 1 for hte number of days worked." #include <iostream> #include <iomanip> using namespace std; int main() { int days, salary; // Initiate the counter double total = 0.0; //Get integer cout << "Enter a positive number\n"; cin >> days; for (; days > 0; days--) { (total+=days*2); } //Display Total cout << fixed << showpoint << setprecision(0); cout << "The salary is $:" << total << endl; system ("pause"); return 0; } |
"Write a program that will predict the size of a population of organisms. The program should ask the user for hte starting number of organisms, their average daily population increase (as a percentage), and the number of days they will multiply. A loop should display the size of the population for each day. *Input Validation* Do not accept a number less that 2 for the starting size of the population. Do not accept a negative number for the average daily population increase. Do not accept a number less than 1 for the number of days they will multiply." #include <iostream> #include <iomanip> using namespace std; int main() { int sorg, dinc, dmul, psize; //Calculations cout << "Whats the starting organisms population size? "; cin >> sorg; cout << "\nWhats the daily average popluation increase (percentage)? "; cin >> dinc; cout << "\nWhats the number of days they will multiply? "; cin >> dmul; psize = sorg; for(int count = 2; count <= dmul; count++) { psize = psize +(sorg * dinc/100); cout << "\nThe size of the population is: "<< psize; } system ("pause"); return 0; } |
|
|
|
|