Циклический ввод цифр

Уровень сложности:

Используя оператор цикла do while, составить программу, которая будет требовать ввод цифр с клавиатуры до тех пор, пока не будет введена цифра 1.

Решение скопировано из комментариев, автор traderML, код простой и понятный, дума, комментаривем по программе не надо. Ниже смотрим исходныйкод:
#include <iostream>
using namespace std;

int main()
{
    int numb;
    do {
    cout << "enter number: ";
    cin >> numb;
    } while( numb != 1 );

    return 0;
}
Смотрим результат работы программы.
CppStudio.com
enter number: 4
enter number: 8
enter number: 15
enter number: 16
enter number: 23
enter number: 42
enter number: 1

Ввел магические цифры из лоста.

Автор: Marienko L.
Дата: 01.10.2012
Поделиться:

Комментарии

  1. odto11

    odto11

    #include <iostream>
    using namespace std;
    
    int main()
    {
        cout << "\t\tЦиклический ввод цифр\n";
        int X = 0;
        do
        {
            cout << "Введите число: ";
            cin >> X;
        } while (X != 1);
    
        return 0;
    }
  2. Иван Ватников

    #include "stdafx.h"
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
    	int n;
    	cout << "Vvedite chisla : " << endl;
    	do cin >> n;
    	while (n != 1);
    	system("pause");
        return 0;
    }
  3. colt

    Тот же код, что и в решении, но с хранением всех введенных переменных:

    #include "stdafx.h"
    #include "iostream"
    #include "windows.h"
    #include "cmath"
    #include "vector"
    
    using namespace std;
    
    int intCount;
    int intTempVar;
    
    int _tmain(int argc, _TCHAR* argv[])
    {  
        SetConsoleCP(1251);
        SetConsoleOutputCP(1251);
    
        while(true)
        {  
            system("CLS");
    		cout<<"Введите число и нажмите \"Enter\" (для выхода введите 1): ";
    		vector<int> vecOfValues(1);
    		intCount=0;
    		do
    			{			
    				cin>>intTempVar;
    				vecOfValues.insert(vecOfValues.end(), intTempVar);
    				intCount++;
    			}
    		while(intTempVar!=1);
    		cout<<"Ввод чисел закончен!\n";
    		cout<<"Ввeдено \""<<intCount<<"\" чисел.\n";
    		system("PAUSE");
        }
        return 0;
    }
  4. gro

    gro

    #include <iostream>
    using namespace std;
    
    int main()
    {
    	setlocale(0,"");
    	int figure=0;
    	cout << "Вводите цифры. Для окончания ввода введите 1 и нажмите Enter\n";
    	do
    	{
    		cin.clear();
    		_flushall();
    		cin >> figure;
    		if (figure <0 || figure > 9 || cin.fail())
    			cout << "Это была не цифра!!!\n";
    	}
    	while(figure!=1);
    	cout << endl;
    	return 0;
    }
  5. Stanislav96

    #include <iostream>
    using namespace std;
    int main (){
        int n;
        do
        cin >> n;
        while (n!=1);
        cout << "End!";
    }
  6. Василий Оболенский

    #include<iostream>
    using namespace std;
    int main()
    {
    	int a ;
    	do {
        cin >> a ;
    	}while(a!=1);
    	
    	return 0 ;
    }

Оставить комментарий

Вы должны войти, чтобы оставить комментарий.