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

SO I am COMPLETELY new to programming and have been tossed into a programming course this semester. Below I will post the program that I thought would work with the problem assigned but I keep getting Errors. I'm sure there is probably a TON of problems with it but keep in mind I have NO idea what I am doing. SO here is the goal / what I am supposed to accomplish. Basically gotta follow 4 rules. (Applying only to numbers less than 999) 1. If the number is evenly divisible by 5, and contains a 6, output "bizz". 2. If has a 6 anywhere in it and is not divisible by 5 output "buzz". 3. If the number has a 6 in it and is divisible by 5 the output is "bozz". 4. If the number doesn't follow any of these rules output the number. (As a side-note, I'm assuming that we can use scanf because we talked about it a bit in class but not sure exactly on how to get this to work. Any responses are greatly appreciated. Please try to bare with me as I am completely new to this.. errr..

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
  #define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
int main ()
{
	int i;
	int hun;
	int ten;
	int one;

		(hun = i / 100)
		(ten = i / 10 % 10)
		(one = i % 10)
		(i = 1; i <= 999; i++)
	
	{
		if ((i % 5) == 0)
			(hun == 6)||(ten==6)||(one==6)
			printf("Number= %d Bozz\n", i);
		else if 
			(hun == 6) || (ten == 6) || (one == 6)
			printf("Number= %d Buzz\n", i);
		else if 
			((i % 5) == 0) 
			printf("Number= %d Bizz\n", i);
		else
			printf("Number= %d\n", i);

	}

	return 0;
}
Last edited on
My bad, my code was a little off. I failed to read your whole exceptions list.
From what your instructions state, #'s 1 and 3 are exactly the same...

Here's my code:
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
#include <stdio.h> //standard input-output header
#include <stdlib.h> //standard library of functions
#define _CRT_SECURE_NO_WARNINGS //Allows for scanning input without the "scan_s" prompt

int main()
{
	/*You can also declare variables of the same type like this:
	int i = 0, hun, ten, one;
	*/
	int i = 0;
	int hun;
	int ten;
	int one;
	hun = (i % 100);
	ten = (i % 10); //Division by zero error. You need to think this one out.
	one = (i % 1);

	scanf_s("%d", &i);
	/*1. If the number is evenly divisible by 5, and contains a 6, output "bizz". 
	2. If has a 6 anywhere in it and is not divisible by 5 output "buzz". 
	3. If the number has a 6 in it and is divisible by 5 the output is "bozz". 
	4. If the number doesn't follow any of these rules output the number.*/
	for (i = 1; i <= 999; i++) {
		if ((i % 5 == 0 && hun == 6) || (i % 5 == 0 && ten == 6) || (i % 5 == 0 && one == 6)) //|| = or, && = and.
			printf("Number= %d Bizz\n", i);
		else if
			((i % 5 != 0 && hun == 6) || (i != 0 && ten == 6) || (i != 0 && one == 6))
			printf("Number= %d Buzz\n", i);
		else if ((i / 5 == 0) || (one == 6))
			printf("Number= %d Bozz\n", i);
		else
			printf("Number= %d\n", i);
	}
	system("pause"); /*Pauses the command prompt/console so the user can read the output. Requires the <stdlib.h> header file.
					 */
	return 0;
}


You'll have to figure out the logic as it's stated in a weird way, but hopefully this helps you get on your feet.
Last edited on
You are almost there, except some braces and commas.

Line 11-14, change to something like:
hun = i / 100;
You'll need the comma ';' and you don't need the braces

Line 17-18, change to something like:
if (i % 5 == 0 && (hun == 6 || ten == 6 || one == 6))
Don't end it with ';' and make sure you use brace to wrap parts correctly

Check out the compiler errors, there're a lots of hints.
Fix first compiler error and build the program again, until you make compiler happy.
Sorry guys, I'm still learning but the tips you gave me are helpful. I changed the code around to sort of follow the one above. I fixed the wording with rule 1. the "Bizz". The program compiles fine now. but I still need to understand how you are getting something like for "bizz" rule, How would i make it display "bizz" when evenly divisible by 5 and does not contain a 6? Also the place for me to be testing when I enter a number what the output is would be the "Start without debugging" option correct? Because when I do, and I enter a number I am just getting a list of numbers from 700-999 followed by "Push any key to continue" and the debug window closes with now "Bizz" "Buzz" or "Bozz" so only number values of 700-999 are showing up. Sorry for being a pain at this. ;-(

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
 #include <stdio.h> 
#define _CRT_SECURE_NO_WARNINGS 
int main()
{
	int i = 0, hun, ten, one;
	hun = (i % 100);
	ten = (i % 10); //Division by zero error. You need to think this one out. (what do you mean by this?)
	one = (i % 1);

	scanf_s("%d", &i);
	/*1. If the number is evenly divisible by 5, and does not contain a 6, output "bizz". <--- fixed the wording sorry
	2. If the number has a 6 anywhere in it and is not divisible by 5 output "buzz".
	3. If the number has a 6 in it and is also divisible by 5 the output is "bozz".
	4. If the number doesn't follow any of these rules output the number.*/
	for (i = 1; i <= 999; i++) {
		if ((i / 5 == 0) || (one == 6)) /* gotta fix this line so that divisible by 5 and not contain 6*/
			printf("Number= %d Bizz\n", i);
		else if
			((i % 5 != 0 && hun == 6) || (i != 0 && ten == 6) || (i != 0 && one == 6))
			printf("Number= %d Buzz\n", i);
		else if ((i % 5 == 0 && hun == 6) || (i % 5 == 0 && ten == 6) || (i % 5 == 0 && one == 6))
			printf("Number= %d Bozz\n", i);
		else
			printf("Number= %d\n", i);
	}
	return 0;
}
You'll learn later on that debugging the program is very helpful and that any time you type "return ""(0 in this case)," it tells you that your program exits with code: return value. It's very useful for understanding where your program fails. You're getting all of the numbers in the output, but the logic is a little off. Keep working at it. I'm sure you'll get it.
Ok thx! I'll try and see what I can get to happen
How's your program? Did you get it to work?
Interesting comparison of language between here:

http://www.cplusplus.com/forum/general/184559/#msg902369


@TheIdeasMan: I'm kind of struggling with the whole concept of OOP. I'm using C++ for the class I'm in, which is Data Structures, but I actually skipped C++ in school. I regret testing out of it lol. I have a general understanding of inheritance, object instantiation, pointers, etc., but I'm not grasping the whole picture so well. I seem to be stumped when it comes to understanding what my entire program is doing or how to code it. I had someone help me get it started and explain it to me as we went along, but I don't understand the beginning part of why things need to be declared where and such. All I really understand about classes is that I can use the name of the class and create an instance of it with any object name. My questions are: How would I use this new object, call the constructor properly, declare static variables in the right places, etc.?


And here:
http://www.cplusplus.com/forum/beginner/184550/#msg902133
You'll learn later on that debugging the program is very helpful and that any time you type "return ""(0 in this case)," it tells you that your program exits with code: return value. It's very useful for understanding where your program fails. You're getting all of the numbers in the output, but the logic is a little off. Keep working at it. I'm sure you'll get it.
Topic archived. No new replies allowed.