Quantcast
Channel: Форум программистов и сисадминов Киберфорум
Viewing all articles
Browse latest Browse all 517206

Мистика какая-то =) - С++ для начинающих

$
0
0
:-|
Вообщем имеется код (решение 3 упражнения к главе 6 книги Прата):
Код:

#include <iostream>
#include<cstdlib>
#include<string>
using namespace std;
int main()
{
        char choice;
        string str1;
        cout << "Please enter one of the following choices:" << endl;
        cout << "c) carnivore\t p) pianist\nt) tree\t g) game\n";
        while (!(choice == 'c' || choice == 'p' || choice == 't' || choice == 'g'))
        {
                cout << "Please enter a c, p, t or g: ";
                cin.get(choice);
                switch (choice)
                {
                case 'c': str1 = "carnivore";
                        break;
                case 'p': str1 = "pianist";
                        break;
                case 't': str1 = "tree";
                        break;
                case 'g': str1 = "game";
                default: continue;
                }
        }
        cout << "A maple is a " << str1 << endl;
        system("pause");
        return 0;
}

При работе программы почему-то два раза подряд выводит текст, но запрос на ввод идет один раз. Как это получается? Ведь за выводом текста сразу идет запрос. Что нужно подкорректировать в коде чтоб нормально пахало?
Вложение 653497

Изображения
Тип файла: gif 70826bf5137b.gif (19.4 Кб)

Viewing all articles
Browse latest Browse all 517206

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>