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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
|
int main() {
double grade;
string name, letter_grade;
cout << "What is your name? (Capitalize the first letter only) " << endl;
cin >> name;
cout << "Hello, " << name << "!" << endl;
cout << "Please enter your numerical grade to see your letter grade. " << endl;
cin >> grade;
if (!cin) die("Invalid Input");
if (cin < 0) die("Invalid Input");
if (name == "Stefan" || name == "Bob")
if (grade <= 50)
{
letter_grade = 'D';
cout << letter_grade << endl;
}
else
if (grade < 65 && grade > 50)
{
letter_grade = 'C';
cout << letter_grade << endl;
}
else
if (grade >= 65 && grade < 75)
{
letter_grade = 'B';
cout << letter_grade << endl;
}
else
if (grade >= 75 && grade < 85)
{
letter_grade = 'A';
cout << letter_grade << endl;
}
else
if (grade >= 85)
{
letter_grade = 'A';
cout << letter_grade << endl;
}
if (name != "Stefan" && name != "Bob")
if (grade <= 50)
{
letter_grade = 'F';
cout << letter_grade << endl;
}
else
if (grade < 65 && grade > 50)
{
letter_grade = 'D';
cout << letter_grade << endl;
}
else
if (grade >= 65 && grade < 75)
{
letter_grade = 'C';
cout << letter_grade << endl;
}
else
if (grade >= 75 && grade < 85)
{
letter_grade = 'B';
cout << letter_grade << endl;
}
else
if (grade >= 85)
{
letter_grade = 'A';
cout << letter_grade << endl;
}
}
bool die(const string & msg) {
cout << "ERROR: " << msg << endl;
exit(EXIT_FAILURE);
}
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
bool die(const string & msg);
int main() {
unsigned x, ax, xa, bx, xb, cx, xc, dx, z;
cout << "Please enter a 4-digit integer: " << endl;
cin >> x;
if (!cin) die("Invalid Input.");
if (x > 9999) die("Number too large.");
if (x < 1000) die("Number too small");
ax = x / 1000; //generates first digit
xa = x % 1000; //generates remainder
bx = xa / 100; //generates second digit
xb = xa % 100; //generates remainder
cx = xb / 10; //generates third digit
xc = xb % 10; //generates remainder
dx = xc / 1; //generates fourth digit
z = (ax) + (bx * 10) + (cx * 100) + (dx * 1000);
cout << x << " squared is " << x*x << endl;
cout << z << " squared is " << z*z << endl;
}
bool die(const string & msg) {
cout << "ERROR: " << msg << endl;
exit(EXIT_FAILURE);
}
#include <iostream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
bool die(const string & msg);
int main() {
unsigned seconds, S, M, MM, H, HH;
cout << "Please enter the total number of seconds: " << endl;
cin >> seconds;
if (!cin) die("Invalid Input");
if (seconds <= 0) die("Invalid Input");
H = seconds / 3600;
HH = seconds % 3600;
M = HH / 60;
MM = HH % 60;
S = MM / 1;
cout << H << ":" << M << ":" << S << endl;
}
bool die(const string & msg) {
cout << "ERROR: " << msg << endl;
exit(EXIT_FAILURE);
}
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
bool die(const string & msg);
int main() {
double A, B, C, D, E, X;
cout << "Please enter 5 test scores you'd like to find the average of." << endl;
cout << "Decimals are an acceptable input" << endl;
cout << "Test score 1: " << endl;
cin >> A;
cout << "Test score 2: " << endl;
cin >> B;
cout << "Test score 3: " << endl;
cin >> C;
cout << "Test score 4: " << endl;
cin >> D;
cout << "Test score 5: " << endl;
cin >> E;
if (!cin) die("Input Failure");
if (A <= 0) die("One or more inputs are negative.");
if (B <= 0) die("One or more inputs are negative.");
if (C <= 0) die("One or more inputs are negative.");
if (D <= 0) die("One or more inputs are negative.");
if (E <= 0) die("One or more inputs are negative.");
double AA, BB, CC, DD, EE;
AA = static_cast<int> (A + .5);
BB = static_cast<int> (B + .5);
CC = static_cast<int> (C + .5);
DD = static_cast<int> (D + .5);
EE = static_cast<int> (E + .5);
X = ((AA + BB + CC + DD + EE) / 5);
cout << "The average (after each score is rounded to the nearest integer) is: " << X << "." << endl;
}
bool die(const string & msg) {
cout << "ERROR: " << msg << endl;
exit(EXIT_FAILURE);
}
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
bool die(const string & msg);
int main() {
int $;
cout << "Hello! Let me sort out your money for you." << endl;
cout << "Please enter the amount of cents that you would like to turn into coins." << endl;
cin >> $;
int Q = $ % 25;
int QQ = $ / 25;
int D = Q % 10;
int DD = Q / 10;
int N = D % 5;
int NN = D / 5;
int PP = N / 1;
if (!cin) die("Invalid Input.");
if ($ <= 0) die("Non existant amount.");
cout << "The following is minimum number of coins you'd have to equal " << $ << " cents:" << endl;
cout << "Quarters: " << QQ << endl;
cout << "Dimes: " << DD << endl;
cout << "Nickles: " << NN << endl;
cout << "Pennies " << PP << endl;
}
bool die(const string & msg) {
cout << "Self destruct initiated: " << msg << endl;
exit(EXIT_FAILURE);
}
#include <iostream>
#include <string>
using namespace std;
bool die(const string & msg);
int main() {
double Q, D, N, P;
double QQ, DD, NN, PP, Total;
cout << "Welcome to your personal piggy bank counter!" << endl;
cout << "" << endl;
cout << "Let me help you count how much money you have based on the coins you have." << endl;
cout << "" << endl;
cout << "How many quarters do you have? ";
cin >> Q;
cout << "How many dimes do you have? ";
cin >> D;
cout << "How many nickles do you have? ";
cin >> N;
cout << "How many pennies do you have? ";
cin >> P;
if (Q + D + N + P > 1000) die("Too many coins.");
if (!cin) die("Bad Input.");
QQ = Q * .25;
DD = D * .10;
NN = N * .05;
PP = P * .01;
Total = QQ + DD + NN + PP;
cout << "Quarters: " << Q << endl;
cout << "Dimes: " << D << endl;
cout << "Nickles: " << N << endl;
cout << "Pennies: " << P << endl;
cout << "You have $" << Total << " in your piggy bank!" << endl;
}
bool die(const string & msg) {
cout << "Self destruct initiated: " << msg << endl;
exit(EXIT_FAILURE);
}
|