Assignment 5 - Phan Minh Phương
Assignment 5 - Phan Minh Phương
1. Sum of Numbers
#include <iostream>
int main(){
int x, sum=0, i;
cin >> x;
while(x<=0){
cin >> x;
sum+=i;
cout<<" The sum of all the integers from 1 up to the number entered "<<x<<" is "<<sum;
return 0;
int main(){
int i;
cout<<" the characters for the ASCII codes 0 through 127: ";
for(i=0; i<=127; i++){
cout<<static_cast<char>(i)<<" ";
if ((i + 1) % 16 == 0){
}}
return 0;
3. Ocean Levels
#include <iostream>
int main(){
int i;
float total;
total=1.5*i;
return 0;
4. Distance Traveled
#include <iostream>
int main(){
cout<<" Do not accept a negative number for speed and do not accept any value less than 1 for time
traveled. ";
cin >>speed>>time;
distance = speed*i;
return 0;
#include <fstream>
int main(){
ifstream Inputfile;
Inputfile.open("People.txt");
if (!Inputfile)
switch (i){
break;
break;
break;
break;
break;
break;
Inputfile>>population;
population /=1000;
cout<<"*";
}
Inputfile.close();
return 0;
#include <iostream>
#include <cstdlib>
#include <ctime>
int main(){
srand(time(0));
int Random_Number_Guessing_Game=rand() % 50 + 1,
number;
do{
cout <<" Asks the user to guess what the number(1-50): ";
if(number<Random_Number_Guessing_Game){
cout<< " Too low, try again. Guess another number: "<<endl;
}else if (number>Random_Number_Guessing_Game){
b.
#include <iostream>
#include <cstdlib>
#include <ctime>
int main(){
srand(time(0));
int Random_Number_Guessing_Game=rand() % 50 + 1,
number,
number_of_guesses = 0;
do{
cout <<" Asks the user to guess what the number(1-50): ";
number_of_guesses++;
if(number<Random_Number_Guessing_Game){
}else if (number>Random_Number_Guessing_Game){
int main(){
switch (i){
break;
break;
break;
break;
cout <<"*";
return 0;
int main(){
while (true){
cout<<" A range of integers: ";
if (numbers == -99)
break;
smallest = numbers ;
largest = numbers;
return 0;
9. Square Display
#include <iostream>
int main(){
cout<<" Asks the user for a positive integer no greater than 15: ";
if (numbers>15){
return 0;
}
if (numbers <= 1 & numbers >= 15){
cout<<"X";
cout<<endl;
return 0;