IF a specific number resides in an integer

I have to build a project for an assignment and I've got everything except for one minor snag. I need to build a game called fizz buzz. In short, it needs to count to 100 and display each integer on the way. However, if the number is divisible by 3, it needs to display fizz, if it's divisible by 5 it needs to display buzz. If the number has a 3 in it, it also needs to display fizz and buzz if it has a 5 in it. Example:

1
2
fizzfizz
4
buzzbuzz
fizz
7
8
fizz
buzz
11
fizz
13
14
fizzbuzzbuzz (because it is divisible by both and has a 5 in it)

My problem isn't the counting or anything like that, the problem I have is that I don't know how to tell the program to look for a specific integer within another integer. Example: If I have 25, how do I tell the program to look for the 5 in that integer and display an additional buzz if it finds one?

Any input you could give me would be much appreciated!

Thanks,
S
Last edited on
You can use / and %. For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <string>
#include <ostream>
int main()
{
    std::cout<<"Wich number (between 1 and 99)?";
    int a;
    std::cin>>a;
    int digit1=a/10;
    int digit2=a%10;
    std::cout<<digit1<<std::endl<<digit2;
    return 0;
}


Last edited on
Topic archived. No new replies allowed.