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
|
//James Wirth, February 13th, 2017
//The purpose of this program is to send a morse coded document with the correct amount of charge and translate each letter if the user is unaware of the identification of a letter to morse.
//I had some trouble trying to figure out the algorithms of converting the amount into a proper coin situated fee. It has something to do with the dollars.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
const int pennyvalue = 1;
const int nickelvalue = 5;
const int dimevalue = 10;
const int quartervalue = 25;
const int dollarvalue = 100;
int wordsSent(int);
void message(string);
void readFile();
int main()
{
int choice;
cout << "Would you like to: " << endl;
cout << "1 - Process your bill or translate code?" << endl;
cout << "2 - Translate to Morse Code?" << endl;
cout << "3 - Process a data file?" << endl;
cout << "4 - Quit?" << endl;
cin >> choice;
while (choice > 4 || choice < 1)
{
cout << "Whoops, you didn't input a correct value. Try again." << endl;
cin >> choice;
}
}
int wordsSent(int)
{
int words, streetnumbers, zip, amount, dollars, quarters, dimes, nickels, pennies, choice, changeindollars, changeinquarters, changeindimes, changeinnickels, changeinpennies;
double total, total1, total2;
string name, street, city, state;
cout << "You've chosen to process your bill." << endl;
//This part of the program asks the user to input info about their info.
cout << "What is your name? ";
cin >> name;
cout << "What are the numbers in your street address? ";
cin >> streetnumbers;
cout << "What is the name of the street you live on? ";
cin >> street;
cout << "What's the city name? ";
cin >> city;
cout << "What's the state? ";
cin >> state;
cout << "What's the zipcode? ";
cin >> zip;
cout << "How many words sent? ";
cin >> words;
//Where the algorithms are made.
total1 = (words/5) * 1.50;
total2 = words * .5;
if (total1<total2)
{
total = total1;
}
else
{
total = total2;
}
//This will display all of the info they put in.
cout << name << endl;
cout << streetnumbers << endl;
cout << street << endl;
cout << city << ", ";
cout << state << ", ";
cout << zip << endl;
cout << words << endl;
cout << "Your fee is " << total << " dollars" <<endl;
cout << endl;
cout << "Enter the amount you want to give in terms of pennies: ";
cin >> amount;
while (amount < total * 100)
{
cout << "Oops, seems like you put in less than the fee. Please try again." << endl; //If a choice isn't one asked for, repeats.
cin >> amount;
}
amount = amount - total * 100;
changeindollars = amount / 100;
amount = amount % 100;
changeinquarters = amount % 100 /25;
amount = amount % 25;
changeindimes = amount % 10;
amount = amount % 10;
changeinnickels = amount % 5;
amount = amount % 5;
changeinpennies = amount % 1;
amount = amount % 1;
cout << "Your change in dollars is: " << changeindollars << endl;
cout << "Your change in quarters is: " << changeinquarters << endl;
cout << "Your change in dimes is: " << changeindimes << endl;
cout << "Your change in nickels is: " << changeinnickels << endl;
cout << "Your change in pennies: " << changeinpennies << endl;
return 0;
}
void message(string)
{
char one, two, letter, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, three;
int choice;
if (choice == 2) //This choice will take the letter inputed, capitalized or not, and return the morse code represention.
{
cout << "Enter a message: " << endl;
cin.ignore();
getline(cin,letter);
if (letter == 'a' || 'A')
cout << "a translates to .-" << endl;
return 0;
if (letter == 'b' || 'B')
cout << "b translates to -..." << endl;
return 0;
if (letter == 'c' || 'C')
cout << "c translates to -.-." << endl;
return 0;
if (letter == 'd' || 'D')
cout << "d translates to -.." << endl;
return 0;
if (letter == 'e' || 'E')
cout << "e translates to ." << endl;
return 0;
if (letter == 'f' || 'F')
cout << "f translates to ..-." << endl;
return 0;
if (letter == 'g' || 'G')
cout << "g translates to --." << endl;
return 0;
if (letter == 'h' || 'H')
cout << "h translates to ...." << endl;
return 0;
if (letter == 'i' || 'I')
cout << "i translates to .." << endl;
return 0;
if (letter == 'j' || 'J')
cout << "j translates to .---" << endl;
return 0;
if (letter == 'k' || 'K')
cout << "k translates to -.-" << endl;
return 0;
if (letter == 'l' || 'L')
cout << "l translates to .-.." << endl;
return 0;
if (letter == 'm' || 'M')
cout << "m translates to --" << endl;
return 0;
if (letter == 'n' || 'N')
cout << "n translates to -." << endl;
return 0;
if (letter == 'o' || 'O')
cout << "o translates to ---" << endl;
return 0;
if (letter == 'p' || 'P')
cout << "p translates to .--." << endl;
return 0;
if (letter == 'q' || 'Q')
cout << "q translates to --.-" << endl;
return 0;
if (letter == 'r' || 'R')
cout << "r translates to .-." << endl;
return 0;
if (letter == 's' || 'S')
cout << "s translates to ..." << endl;
return 0;
if (letter == 't' || 'T')
cout << "t translates to -" << endl;
return 0;
if (letter == 'u' || 'U')
cout << "u translates to ..-" << endl;
return 0;
if (letter == 'v' || 'V')
cout << "v translates to ...-" << endl;
return 0;
if (letter == 'w' || 'W')
cout << "w translates to .--" << endl;
return 0;
if (letter == 'x' || 'X')
cout << "x translates to -..-" << endl;
return 0;
if (letter == 'y' || 'Y')
cout << "y translates to -.--" << endl;
return 0;
if (letter == 'z' || 'Z')
cout << "z translates to --.." << endl;
return 0;
}
}
void readFile()
{
ifstream inputFile;
string yes, data, input;
int choice;
if (choice == 3) //A file will be read through this choice displaying the informatino with the text file.
{ //Didn't know how to do proper spaces after each subject.
inputFile.open("TelegramData.txt");
while (inputFile >> data)
{
cout << data << endl;
}
inputFile.close();
}
if (choice == 4) //Closes program.
{
cout << "Thank you. Closing program." << endl;
exit(0);
}
}
|