Help with while loop
Nov 3, 2016 at 2:57am UTC
Write your question here.For my code, multiples of 5 should be changed to Humpty, multiples of 7 should be changed to Dumpty, and multiples of 35 should changed to Had a Great Fall.
For some reason the number is next to the word, and I can't figure out how to get rid of the number
Ex: Humpty5
Dumpty7
Had a Great Fall35
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
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int counting = 1;
while (counting < 40)
{
cout << counting;
cout << endl;
counting++;
if (counting % 35 == 0)
{
cout << "Had a Great Fall" ;
}
else if (counting % 5 == 0)
{
cout << "Humpty" ;
}
else if (counting % 7 == 0)
{
cout << "Dumpty" ;
}
}
}
Nov 3, 2016 at 3:14am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
cout << counting;
cout << endl;
counting++;
if (counting % 35 == 0)
{
cout << "Had a Great Fall" ;
}
else if (counting % 5 == 0)
{
cout << "Humpty" ;
}
else if (counting % 7 == 0)
{
cout << "Dumpty" ;
}
Should be :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
if (counting % 35 == 0)
{
cout << "Had a Great Fall" ;
}
else if (counting % 5 == 0)
{
cout << "Humpty" ;
}
else if (counting % 7 == 0)
{
cout << "Dumpty" ;
}
else
{
cout << counting;
}
cout << endl;
counting++;
Topic archived. No new replies allowed.