我希望我的循环以'。'结尾。烧焦 [英] I want my loop to end with a '.' char

查看:95
本文介绍了我希望我的循环以'。'结尾。烧焦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

这个程序要求

从键盘上读取一系列的
tters(大写或小写)和将

中相应的大写字母

保存到一个字符向量(

vector< char>

)中,直到用户输入

字符。 (句号),不应插入向量中的
;字母以外的字符或

以前输入的字符

ly不应插入到矢量中。

显示结果矢量屏幕,

使用示例中显示的格式。



示例:

LETTER或。 ? r

LETTER或。 ? T

LETTER或。 ? 2

//无效字符;它没有插入到矢量中

LETTER或。 ? t

//重复的信件;它没有插入到矢量中

LETTER或。 ? P

LETTER或。 ? 。

矢量:[RTP]



Hi!
This program asks to
Read, from the keyboard, a sequence of le
tters (uppercase or lowercase) and save the
corresponding uppercase letter in
to a vector of characters (
vector<char>
) until the user enters the
character "." (period), which should not be inserted in
to the vector; characters other than letters or
characters that have already been typed previous
ly should not be inserted into the vector.
Present the resulting vector on the screen,
using the format shown in the example.

Example:
LETTER or "." ? r
LETTER or "." ? T
LETTER or "." ? 2
// invalid character; it not inserted into the vector
LETTER or "." ? t
// repeated letter; it not inserted into the vector
LETTER or "." ? P
LETTER or "." ? .
VECTOR: [ R T P ]

#include <iostream>
#include <ctime>
#include <ctype.h>
#include <vector>

using namespace std;

char* UCASE(char s[256]){
   for(int i=0;s[i]!='\0';i++)
	{
		s[i]=toupper(s[i]);
	}
   return s;
}

int isletter(char s)
{
	int i;
	if (isalpha(s))
	    {i =1;}
	else
	    {i=0;}

	return i;
}



int main(){

	char letter[256];
	char ter;
	ter = atoi(letter);
	char end = '.';

	vector<char> v;


    do
    {cout << "LETTER OR '.' ? ";
    cin >> letter;
    char finletter;
    finletter = atoi(UCASE(letter));

    	if ( !(find(v.begin(), v.end(), finletter) !=v.end()) && isletter(ter)==1)
    {

    	v.push_back(finletter);
    };

    } while (ter!=end);

    {      cout << "VECTOR: [ ";

        	for (size_t n = 0; n < v.size(); n++)
        	    cout << v[ n ] << " ";
        	    cout << " ]" << endl;}


	return 0;
};







输出正确地询问字母,但是当放'时它继续回答一封信,而不是显示向量。

我曾经尝试过(ter!='。')然后我用do做了,但它没有解决任何问题。

你能帮帮忙吗?




The output is asking correctly for the letters, but when putting '.' it continues to answer for a letter instead of displaying the vector.
I've tried just while(ter!='.') and then i did it with do while but it didn't resolve anything.
Can you help?

推荐答案

你读取输入到finletter,但循环是比较ter。 ter永远不会在循环中设置。
You read the input into finletter, but the loop is comparing ter. ter is never set inside the loop.


这篇关于我希望我的循环以'。'结尾。烧焦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆