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 76 77 78 79
|
/*
Introduction to C++ Getting Started
Programs:
1. Create a program that announces “Good Morning, Planet Earth!” to the user.
2. Of course, in the event that it’s late at night, create another program that announces, “Good Evening, Planet Earth!”
3. Create a program that asks the user for their height in feet, and stores that into an int variable.
Print out their height in inches.
4. Create a program that asks the user for their weight in pounds. In the United Kingdom,
it is common to express a person’s weight in “stone”, which is approximately 0.0714 stone to the pound. Print out their weight in stone.
5. Find out today’s spot price for gold per troy ounce (or just use US$1000).
One pound of weight is equal to approximately 14.583 troy ounces.
Create a program that asks the user for their weight in pounds, then prints out:
You are worth US$worth in gold!
Calculate “worth” by multiplying the weight by 14.583 and the price of gold.
6. Create a program that first asks the user for their first name, second asks for their middle initial, and then finally asks for their last name.
Print out their name as:
Your name is: last name, first name middle initial
where, of course, the actual last name, first name and middle initial are used.
Remember that people’s names very often more than one word, so you’ll need to read an entire line at a time.
*/
#include <iostream>
using namespace std;
int main()
{
//Program 1
cout << "Good Morning, Planet Earth!" << endl;
//Program 3
int height;
cout << "What is your height in feet? ";
cin >> height;
int feet_converted_inches = (height * 12) ;
cout << "Your height in inches is " << feet_converted_inches << endl;
//Program 4
int weight;
cout << "Whats your weight in pounds? ";
cin >> weight;
double weight_to_stone = (0.0714 * weight);
cout << "Your weight in stone is " << weight_to_stone << endl;
//Program 5
int lb;
cout << "What is your weight in pounds? " ;
cin >> lb;
double weight_of_lb_of_troy = (lb * 14.583);
double final_weight = weight_of_lb_of_troy*1000;
cout << "Your are worth US $ " << final_weight << "in gold!" << endl;
//Program 6
double first,
middle,
last;
cout << "Whats your first name: ";
cin >> first;
cout << "Whats your middle initial: ";
cin >> middle;
cout << "Whats your last name: ";
cin >> last;
cout << last << " , " << first << " " << middle << endl;
return 0;
}
|