aboutsummaryrefslogtreecommitdiff
path: root/CST116F2021-Lab5/CST116F2021-Lab5(2).cpp
blob: 20fea9f44535123e5b441cbd72cdfc04b60b1955 (plain) (blame)
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
#include "CST116F2021-Lab5(Header).h"

//10a
//9.4 Learn by Doing Exercises

//function getName definition
//void getName(char first[], char last[])
//{
//	cout << "Please enter your first name: ";
//	cin >> first;
//	cout << "Please enter your last name: ";
//	cin >> last;
//}

//function formatName definition
//void formatName(char first[], char last[])
//{
	//defining local array and counter variable
//	char fullName[32] = {};
//	int letterCount = 0;
//	int letterCountOffset = 0;
	//copy first to fullName character by character
//	while (last[letterCount] != '\0')
//	{
//		fullName[letterCount] = last[letterCount];
//		letterCount++;
//		letterCountOffset++;
//	}
	//add comma and space to fullName after first
//	fullName[letterCount] = ',';
//	letterCount++;
//	letterCountOffset++;

//	fullName[letterCount] = ' ';
//	letterCount++;
//	letterCountOffset++;
	//copy last to fullName character by character
//	while (first[letterCount-letterCountOffset] != '\0')
//	{
//		fullName[letterCount] = first[letterCount-letterCountOffset];
//		letterCount++;
//	}

//	cout << fullName;
//}

//10b
//9.5 Learn by Doing Exercises

//function getStrings definition
void getStrings(char firstString[], char secondString[])
{
	//get firstString
	cout << "Please enter your first string (at least six characters)\n";
	cin >> firstString;
	//get secondString
	cout << "Please enter your second string (at least six characters)\n";
	cin >> secondString;
}

//function compareStrings definition
void compareStrings(char firstString[], char secondString[])
{
	//comparison
	for (int count = 0; count < 5; count++)
	{
		if (firstString[count + 1] == '\0' || secondString[count + 1] == '\0')
		{
			//error message
			cout << endl << "ERROR: both strings must be at least six characters.\n";
			return;
		}
	}

	for (int count = 0; count <= 5; count++)
	{
		if (firstString[count] != secondString[count])
		{
			//different message
			cout << endl << "The first six characters of your two strings are different.\n";
			return;
		}
	}

	//same message
	cout << endl << "The first six characters of your two strings are the same\n";
	return;
}