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
|
// 3 Negative Numbers.cpp : main project file.
#include "stdafx.h"
#include <iostream>
#include <windows.h>
using namespace std;
/*
bool numbers();
int main()
{
bool Neg_Num=false;
do
{
cout << endl << "3 Negative numbers to end program"<< endl << endl << "Enter 3 positve numbers... ";
Neg_Num = numbers();
}while(!Neg_Num);
cout << endl << endl << "I see you are ending the program. Good-bye!!" << endl << endl;
return 0;
}
bool numbers()
{
bool negative = false;
int x,y,z;
int sum;
cout << endl << "X = ";
cin >> x;
cout << "Y = ";
cin >> y;
cout << "Z = ";
cin >> z;
if(x<0 && y<0 && z<0)
{
negative=true;
return negative;
}
sum = x+y+z;
cout << "The sum of " << x << ", " << y << " and " << z << " equal " << sum;
return negative;
}*/
const int lucky=6;
void introduction();
int findouthowmany (int x, int y, int z);
int didtheproducthit (int x, int y);
int main()
{
int x, y, z, data=0, total;
introduction();
do
{
cout<< "Type three integers" << endl;
cin >> x >> y >> z;
total = findouthowmany (x, y, z);
if (total != -1)
{
cout<< total << " numbers are equal to the lucky number 6" << endl;
didtheproducthit (x,y);
didtheproducthit (y,z);
didtheproducthit (x,z);
cout<< endl << endl;
data++;
}
} while (data < 8 && total >= 0);
if(total <0)
{
cout << endl << "Three negative numbers were entered. Program is ending.." << endl;
}
cout<< data << " sets of three data values were entered and processed." << endl;
return 0;
}
// introdcution has no parameters and will print out a message on top of the program explaining what it will do.
void introduction()
{
cout<< "My lucky number is 6. This program will end when there are at least eight\nsets of data values or if the user types in all negative numbers." << endl << endl;
// return; Not really needed. Returns on its own when function ends
}
//findouthowmany will determine how many of the three integers: int x, y, and z
//are equal to the lucky number. it will print how many of the three numbers are equal.
int findouthowmany (int x, int y, int z)
{
int count=0;
if(x<0 && y<0 && z<0)
{
count = -1;
return count;
}
if (lucky==x)
count++;
if (lucky==y)
count++;
if (lucky==z)
count++;
return count;
}
//didtheproducthit will determine whether or not the product of parameter x and y values
//equal the lucky number and it will print a comment saying whether or not they multiply to 6.
//this function will repeat three times in the main function.
int didtheproducthit (int x, int y)
{
if (lucky==x*y)
cout<< x << " times " << y << " multiply to 6" << endl;
else
cout<< x << " times "<< y << " do not multiply to 6" << endl;
return 0;
}
|