cpp6.1

来源:互联网 发布:淘宝亲宝贝什么意思 编辑:程序博客网 时间:2024/06/05 21:05

6.1

#include<iostream>int main(){using std::cin;using std::cout;char ch;int spaces = 0;int total = 0;cin.get(ch);while (ch != '.'){if (ch == ' ')++spaces;++total;cin.get(ch);}cout << spaces << " spaces, " << total;cout << " characters tatal in sentence\n";system("pause");return 0;}


6.2

#include<iostream>int main(){char ch;std::cout << "Type, and I shall repeat. \n";std::cin.get(ch);while (ch!='.'){if (ch == '\n')std::cout << ch;elsestd::cout << ++ch;std::cin.get(ch);}std::cout << "\nplease excuse the slight confusion.\n";system("pause");return 0;}


6.3

#include<iostream>const int Fave = 27;int main(){using namespace std;int n;cout << "Enter a number in the range 1-100 to find ";cout << "My favorite number: ";do{cin >> n;if (n < Fave)cout << "Too low--guess again: ";else if (n > Fave)cout << "Too high--guess again: ";elsecout << Fave << " is right!\n";} while (n != Fave);system("pause");return 0;}


0 0
原创粉丝点击