Технический форум

Технический форум (http://www.tehnari.ru/)
-   Помощь студентам (http://www.tehnari.ru/f41/)
-   -   Написать программу. С++ (http://www.tehnari.ru/f41/t91933/)

denisko1 29.10.2013 23:54

Написать программу. С++
 
Написать программу для определения стоимости разговора по телефону с учетом скидки 20%, которая предоставляется в субботу и воскресенье.

Программу нужно написать с помощью конструкции switch-case.

Помогите пожалуйста. Заранее спасибо.

Gruvi 30.10.2013 02:20

Вот программа, надеюсь разберешься сам=)
Цитата:

int main()
{
setlocale (LC_ALL, ".1251");
int day;
float stoim, prod;
float res;
cout<< "Введите стоимоть одной минуты\n";
cin>>stoim;
cout<<"Введите продолжительность\n";
cin>>prod;
cout << "Введите день\n";
cin>>day;
if (day == 1)
res = stoim*prod;
else if (day == 2)
res = stoim*prod;
else if (day == 3)
res = stoim*prod;
else if (day == 4)
res = stoim*prod;
else if (day == 5)
res = stoim*prod;
else if (day == 6)
res = stoim*0.8*prod;
else if (day == 7)
res = stoim*0.8*prod;
cout<<"стоимость разговора ="<<res<<endl;
cout<<endl<<"нажмите выход для завершения работы программы"<<endl;
string s;
do {} while (s.find("exit")==string::npos);
return 0;
}

grelly 30.10.2013 14:37

switch - case же надо)
Код:

switch(day)
{
    case 1:
        res = stoim*prod;
    case 2:
        res = stoim*prod;
    case 3:
        res = stoim*prod;
    case 4:
        res = stoim*prod;
    case 5:
        res = stoim*prod;
    case 6:
        res = stoim*0.8*prod;
    case 7:
        res = stoim*0.8*prod;
}

или так

switch(day)
{
    case 6:
        res = stoim*0.8*prod;
    case 7:
        res = stoim*0.8*prod;
    default:
        res = stoim*prod;
}

в каждый case надо еще добавить оператор break


Часовой пояс GMT +4, время: 15:45.

Powered by vBulletin® Version 4.5.3
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.