I'm fairly new to C++ and i'm doing a coding assignment where a user imputed integer between 10 and 100 will output "Music" (Sounds written out) and for each time a sound is played the program adds one "Snack" to a certain animal.
#include <iostream>
usingnamespace std;
int main ()
{
int se = 0; //Snacks for El Chupacabra
int sb = 0; //Snacks for Buck Toothed Slug
int sf = 0; //Snacks for Freaky Fish
int sl = 0; //Snacks for Three-Legged Snakes
int st = 0; //Snacks for Trash Bears
int sh = 0; //Snacks for Hans
int sc = 0; //Snacks for Cletus
int in = 0; //The Inspirational Number
//Greeting
cout << "Welcome to the Snax-A-Thon Music Maker!" << endl;
//Promt the user for the Inspirational Number
cout << "Please enter an integer between 10 and 100:" << endl;
cin >> in;
//Test the Inspirational Number
while((in < 10) || (in > 100)){
cout << "Please use an integer between 10 and 100:" << endl;
cin >>in;
}
if((in > 10) && (in < 100)){
cout << in << " will be used as your Inspirational Number!" << endl;
}
//Create some music
do{
if((in == 0 || 7 || 14 || 21 || 28 || 35 || 42 || 49 || 56 || 63 || 70 || 77 || 84 || 91 || 98 )) {se++; cout << " wah" ; }
if((in == 1 || 8 || 15 || 22 || 29 || 36 || 43 || 50 || 57 || 64 || 71 || 78 || 85 || 92 || 99 )) {sb++; cout << " bleep" ; }
if((in == 2 || 9 || 16 || 23 || 30 || 37 || 44 || 51 || 58 || 65 || 72 || 79 || 86 || 93 || 100 )) {sf++; cout << " do-wah" ; }
if((in == 3 || 10 || 17 || 24 || 31 || 38 || 45 || 52 || 59 || 66 || 73 || 80 || 87 || 94 )) {sl++; cout << " ding" ; }
if((in == 4 || 11 || 18 || 25 || 32 || 39 || 46 || 53 || 60 || 67 || 74 || 81 || 88 || 95 )) {st++; cout << " honk" ; }
if((in == 5 || 12 || 19 || 26 || 33 || 40 || 47 || 54 || 61 || 68 || 75 || 82 || 89 || 96 )) {sh++; cout << " wapp" ; }
if((in == 6 || 13 || 20 || 27 || 34 || 41 || 48 || 55 || 62 || 69 || 76 || 83 || 90 || 97 )) {sc++; cout << " DOH!" ; }
if(in%2 == 0) {in = (in/2);}
if(in%2 != 0) {in = (3*in)+1;}
} while (in >=1);
//output the snacks
cout << "El Chupacabra got " << se << " snacks!" << endl;
cout << "Buck-Toothed Slug got " << sb << " snacks!" << endl;
cout << "Freaky Fish got " << sf << " snacks!" << endl;
cout << "Three-Legged Snakes got " << sl << " snacks!" << endl;
cout << "Trash Bears got " << st << " snacks!" << endl;
cout << "Hans got " << sh << " snacks!" << endl;
cout << "Cletus got " << sc << " snacks!" << endl;
return 0;
}
Whenever I run it as is the only output I ever get (With a valid in) is a constant run of "Wah bleep do-wah ding honk wapp DOH!"
I could use any help I could get at this point, even if I have to rewrite it, i'm not smart enough on terminology to be able to google my way through anymore.
PS (Sorry for the sloppy display of code, copy pasta did not like Notepad++ to forum.
The way you have your while loop set up if a valid number is entered it can never break out of the do while loop. I also don't understand what you are trying to do with this code here:
One thing I have tried was to change the condition in the while statement to while (in >= 1 && in < 50). This worked for the numbers 11,15,17 that I tried.The other numbers seemed to be endless loops. When I changed the 50 to 100 different numbers worked while the others did not.