DO WHILE LOOP C++

CAN I ASK FOR YOUR CODE ON THIS, THAT THE OUTPUT MUST BE


Enter how may number:5
10
5
100
4
56

Number/s ends with zero: 10 100
Insufficient information.

Where do the numbers come from?
- Are those random numbers?
- Is the user prompted for the numbers?
- Are the numbers read from a file?
- Can the numbers be in a static array?

Number/s ends with zero: 10 10

What does that mean?
Last edited on
that numbers are the examples

that enter how many numbers: 5
it means I can put 5 numbers from 1-100


and the number/s end with zero: 10 100
it will show if there's a zero within the number I input

even i do, i don't understand what my professor wants us to do.




Well x ends in zero, if x % 10 == 0.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <cctype>
#include <limits>

int main()
{
   std::cout << "Do you want someone to do all the work for you? ";
   char answer{};
   std::cin >> answer;

   std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');

   if (std::toupper(answer) == 'Y' ) { std::cout << "Post it in the Jobs section.\n"; }

   else { std::cout << "Show what you have coded so far.\n"; }

   std::cout << "Good luck.\n";
}
@Furry Guy - I like that. You're missing a do/while loop though.

@OP
Here's the best I can offer based on your very poor description.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
using namespace std;

int main()
{	
	int number; 
	do
	{	//	Get number from somewhere	
		//	Output the number
		cout << number << endl;
		//	Do something if the number has a zero in it.		
		//	Loop until the number is zero
	} while (number);
	return 0;
}


Heh, the do/while loop went MIA.
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <type_traits>
#include <limits>
#include <iostream>
#include <string>
#include <cctype>
#include <vector>

template<typename T = int>
typename std::enable_if_t< std::is_integral_v<T>, T>
getInp(const std::string& prm)
{
	const auto notsp {[&]() {while (std::isspace(static_cast<unsigned char>(std::cin.peek())) && std::cin.peek() != '\n') std::cin.ignore(); return std::cin.peek() != '\n'; }};
	T n {};

	while ((std::cout << prm) && (!(std::cin >> n) || notsp())) {
		std::cout << "Invalid input. Not a(n) " << typeid(T).name() << '\n';
		std::cin.clear();
		std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
	}

	std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
	return n;
}

template<typename T = int>
typename std::enable_if_t< std::is_integral_v<T>, T>
getInp(const std::string& prm, T low, T upper = std::numeric_limits<T>::max())
{
	T num {};

	do {
		num = getInp<T>(prm);
	} while ((num < low || num > upper) && (std::cout << "Input not in range\n"));

	return num;
}

int main() {
	constexpr size_t minno {1}, maxno {100};
	std::vector<int> is10;
	const auto nonums {getInp<size_t>("Enter how many numbers: ")};

	for (size_t n = 1; n <= nonums; ++n) {
		const auto no {getInp("Enter number " + std::to_string(n) + " (" + std::to_string(minno) + " - " + std::to_string(maxno) + "): ", minno, maxno)};

		if (no % 10 == 0)
			is10.emplace_back(no);
	}

	std::cout << "\nNumbers ending with 0: ";

	for (const auto& n : is10)
		std::cout << n << ' ';

	std::cout << '\n';
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <string>
using namespace std;

int main()
{
   string result, s;
   int n;
   cout << "How many numbers? ";   cin >> n;
   cout << "Enter " << n << " numbers: ";
   while ( n-- )
   {
      cin >> s;
      if ( s.back() == '0' ) result += s + ' ';
   }
   cout << "Numbers (or other entities) ending in 0 are: " << result << '\n';
}


How many numbers? 5
Enter 5 numbers: 10 5 100 4 56
Numbers (or other entities) ending in 0 are: 10 100 
Topic archived. No new replies allowed.