Bizz, Buzz, Bozz Beginner C++ Program for Class

Pages: 12
SO I am completely new to programming and haven't written a successful code yet, but I was thrown into a programming class with little to no knowledge. I have been learning some of the rules but I am still really lost. For this program there are 4 rules I have to follow.
1. If the number is evenly divisible by 5, and does not contain a 6, output "bizz" once (not the number); for example 20, 280, 555.
2. If the number has a 6 anywhere in it, and is not evenly divisible by 5, output "buzz" once (not the number); for example 26,61, 262
3. If the number is evenly divisible by 5, and also contains a 6, output "bozz" once (not the number); for example 65, 620, 165
4. If none of these conditions is true, just output the number.

Example of what it should look like ====

Number: 34
Output: 34
Press any key to continue...

Number: 280
Output: bizz

Number: 265
Output: bozz

This program only needs to work for numbers input that are from 1-999. Again I am completely lost on this stuff so any help is greatly appreciated. Just keep in mind I have 0 knowledge on what I am doing haha.
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
  #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
void main()
{
	int number, bizz, buzz, bozz;
	int hund = number / 100;
	int tens = number / 10 % 10;
	int ones = number % 10;

	printf("Enter a number:\n");
	scanf("%d %d %d %d", number, bizz, buzz, bozz);

	(hund != 6) || (tens != 6) || (ones != 6);
	number % 5 == 0;
	printf("bizz is %d", bizz);

	(hund == 6) || (tens == 6) || (ones == 6);
	number % 5 != 0;
	printf("buzz is %d", buzz);

	(hund == 6) || (tens == 6) || (ones == 6);
	number % 5 == 0;
	printf("bozz is %d", bozz);

	(hund != 6) || (tens != 6) || (ones != 6);
	number % 5 != 0;
	printf("number is %d", number);
}
Hey =)

A few things.

void main() should be : int main()

printf and scanf is C, not c++ - http://www.cplusplus.com/doc/tutorial/basic_io/

Learn about basic input and ouput from the link I provided. You'll also need to learn about if statements - http://www.tutorialspoint.com/cplusplus/cpp_if_else_statement.htm

It sounds like you're gonna need to use std::string (letters rather than numbers like int) for this assignment, so you can check whether or not it contains the number 6.
Last edited on
Wow thanks err this is really difficult stuff I appreciate the help... so guess I have been learning about the wrong language for this project errr back to square one =( thanks again though haha
If this is an intro class and the very first assignment then it's kinda harsh. But you have the right idea!
number % 5 == 0; this is something you'll definitely need.
Last edited on
Ok thanks, yeah first time programming ever really... err
But take it step by step.

Create a string -The String Class in C++: (at the very bottom)
http://www.tutorialspoint.com/cplusplus/cpp_strings.htm


Ask the user for a number and assign it to the string -
http://www.cplusplus.com/doc/tutorial/basic_io/


For the first one, you're gonna need to use a for-loop and if statements. that loops through the entire string and makes sure there is no 6.
http://www.tutorialspoint.com/cplusplus/cpp_loop_types.htm
http://www.tutorialspoint.com/cplusplus/cpp_if_statement.htm


If it does not contain a 6, you then need to convert it to an integer again -
http://stackoverflow.com/questions/7663709/convert-string-to-int-c To check if it is dividable with 5. If it is then you print out "bizz"
Last edited on
Woah sounds like you have this all figured out xD but the problem I'm getting now is that the #include <string> isn't including in the program I don't believe. Because when I try and mark something like string str1 = "bizz" the string word won't light up blue indicating the creation of a string.
string, cout (the output instead of printf), cin (input instead of scanf) and many others are part of the standard library. You can google more on that, point is, you'll need std:: to use them.

for example -

1
2
std::string str1 = "bizz";
std::cout << str1 << std::endl;


Or, you can just put using namespace std; above main and you dont have to type std::, But that is not recommended at all since it will only create problems later on - http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice

(You probably wont understand anything in that link)
Last edited on
True xDD
Well I know it is still really bad but here is what i have mess it up to look like now haha
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
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
	int number = 60;
	int hund = number / 100;
	int tens = number / 10 % 10;
	int ones = number % 10;

	printf("Enter a number:\n");

	if ((number % 5 == 0 && hund != 6) || (number % 5 == 0 && tens != 6) || (number % 5 == 0 && ones != 6))
	{
		cout << "Output: bizz\n;" << end1;
	}
		((number % 5 != 0 && hund == 6) || (number % 5 != 0 && tens == 6) || (number % 5 != 0 && ones == 6));
		cout << "Output: buzz\n;" << end2;

		((number % 5 == 0 && hund == 6) || (number % 5 == 0 && tens == 6) || (number % 5 == 0 && ones == 6));
		cout << "Output: bozz\n;" << end3;

		((number % 5 != 0 && hund != 6) || (number % 5 != 0 && tens != 6) || (number % 5 != 0 && ones != 6));
		cout << "Output: number\n;" << end4;
{

	return 0;
}


Oh cool thx for the tip on editing posts I think I am getting something going. Thanks for the help I think I can handle it with the help from the links too =)
Last edited on
PM me your skype and I'll help you out personally if you'd like, just to get you on the right track.

Edit: Btw you can edit your posts instead of keep making new posts :p

Edit 2: Otherwise make sure to really study the links I gave you before you continue. There are also lots of videos on youtube explaining how these things work if you like that.
Last edited on
Sorry don't know if you are still here but I ended up getting this and it builds fine and I can go into the debug terminal and enter a number. Problem is it is only giving me an output of "bizz"any ideas?
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
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
int main()
{
	using std::cout;
	using std::endl;
	using std::cin;
	int number = 0;
	int hund = number / 100;
	int tens = number / 10 % 10;
	int ones = number % 10;

	cout << "Enter a number:\n" << endl;

	cin >> number;
	if ((number % 5 == 0 && hund != 6) || (number % 5 == 0 && tens != 6) || (number % 5 == 0 && ones != 6))
		cout << "Output: bizz\n" << endl;
	
	else if((number % 5 != 0 && hund == 6) || (number % 5 != 0 && tens == 6) || (number % 5 != 0 && ones == 6))
		cout << "Output: buzz\n" << endl;

	else if	((number % 5 == 0 && hund == 6) || (number % 5 == 0 && tens == 6) || (number % 5 == 0 && ones == 6))
		cout << "Output: bozz\n" << endl;

	else if	((number % 5 != 0 && hund != 6) || (number % 5 != 0 && tens != 6) || (number % 5 != 0 && ones != 6))
		cout << "Output: number\n" << endl;

		system("pause");
		return 0;
}


Actually the number % 5 == 0 works i just need to find a string of code to work for find out if a number has a 6 in it guess this, ((number % 5 != 0 && hund != 6) || (number % 5 != 0 && tens != 6) || (number % 5 != 0 && ones != 6)) won't cut it err
Yea I guess after would work better, I'll try it out haha
Last edited on
1
2
3
int hund = number / 100;
int tens = number / 10 % 10;
int ones = number % 10;

Do you want to be doing these calculations before the user gives a number or after? Because right now it's before and it doesnt make much sense^^ You probably want after.
Wait I'm confused, I set it up like that because i figure that I marked those 3 lines so that hund, tens, and ones = assigned variables in which they would be inserted to parts like this ((number % 5 == 0 && hund != 6) || (number % 5 == 0 && tens != 6) || (number % 5 == 0 && ones != 6)) so for example if "number" is divisible by 5 and "hund" which would be the variable and it would do the calculation then right? so && "number / 100 !=6 means does not = 6
Sorry but I literally have no idea what any of what you said means :D

Consider this -

1
2
int number = 0;
int hund = number / 100;


hund will be 0, because 0 / 100 is 0.
Last edited on
1
2
3
4
int number = 0;
int hund = number / 100;
int tens = number / 10 % 10;
int ones = number % 10;


I know you think you're establishing relationships between these numbers, but you're not. There is no such thing as an equation in C++.
Yeah i see that, the part that confuses me most about this project is the fact that I don't know weather He want's to be inputting the numbers through the debug terminal to get answer or if he wanted to just change the "number" value right in the code since it is a beginners project. Not sure if it matters though. And I made "number 0" because it won't allow me to use it as a cin further down the code unless it is assigned a value err
Oh really? ergh well then are you saying that hund, tens, and ones, can't be assigned to = the expression that would check for 6? err
Last edited on
Perhaps you could post your full instructions?
You are to write a program to help a person play the game of "bizz-buzz-bozz". Although there are several different versions of the game, generally players sit in a circle. The first player starts by saying "1". Play continues around the circle with the next player saying "2", and so on...UNLESS any of the following conditions are met, in which case the player says "buzz", "bizz", or "bozz". You are to write a program, that given a number will either parrot back the number or print "buzz" or print "bizz" or print "bozz" if various conditions are met.
If the number is evenly divisible by 5, and does not contain a 6, output "bizz" once (not the number); for example 20, 280, 555.
If the number has a 6 anywhere in it, and is not evenly divisible by 5, output "buzz" once (not the number); for example 26, 61, 262
If the number is evenly divisible by 5, and also contains a 6, output "bozz" once (not the number); for example 65, 620, 165
If none of these conditions is true, just output the number.
Some run examples (user input is underlined in example. You do not have to underline the user input):
Number: 34
Output: 34
Press any key to continue...
Number: 280
Output: bizz
Press any key to continue...
Number: 265
Output: bozz
Press any key to continue...
Number: 372
Output: 372
Press any key to continue...
Number: 671
Output: buzz
Press any key to continue...
The largest value your program must handle is 999. The "Press any key to continue..." is not output by your program, but by Visual Studio when you select "Start without debugging".
Checking for divisibility by 5, and if a number contains a 6:
A number is evenly divisible by 5 if number%5==0.
To check for 6's in a number, you can %10 and /10. For example:
hund=n/100; tens=n/10%10; ones=n%10;
The above examples are not an exhaustive list of tests. I will check other values...you should too. You do not have to verify that the entered value is less than 1000. Your program will only be tested with values between 1 and 999.
Pages: 12