Похожие чаты

Hi! How can i make this (C++)? H

HE
HEL
HELL
HELLO

13 ответов

8 просмотров

use loop inside loop. inner loop for iterating letters and spaces. external - for iterating rows

no. this code works. but look at this from another side. what if you need to do the same with another word e.g. "world"? or what if word is 100500 letters long?

maybe a FOR loop ?

علیرضا
Please send me a better solution

no. this chat is for explaining, but not for giving final solutions. just try to write next: 1. your word is an array of symbols 2. loop iterating from 0 to word length minus 1 (which means you iterating rows) 3. loop inside previous from 0 to previous loop index 4. inside this loop print symbol 5. if you need to print spaces before symbols to draw triangle - just calculate the count length/2-inner index

Mihai
maybe a FOR loop ?

include <iostream> using namespace std; int main() { for (string i = H; i < HELLO; i++) {   if (i == HELLO) {     break;   }   cout << i << "\n"; }  return 0; }

artemetra 🇺🇦 [less active]
i++ is not defined for std::string

Language C++ Input include <iostream> using namespace std; int main() { for (string i = H; i < HELLO; i++) {   if (i == HELLO) {     break;   }   cout << i << "\n"; }  return 0; } Output /usercode/file.cpp:5:4: error: stray '\302' in program for (string i = H; i < HELLO; i++) { ^ /usercode/file.cpp:5:5: error: stray '\240' in program for (string i = H; i < HELLO; i++) { ^ /usercode/file.cpp:5:13: error: stray '\302' in program for (string i = H; i < HELLO; i++) { ^ /usercode/file.cpp:5:14: error: stray '\240' in program for (string i = H; i < HELLO; i++) { ^ /usercode/file.cpp:5:18: error: stray '\302' in program for (string i = H; i < HELLO; i++) { ^ /usercode/file.cpp:5:19: error: stray '\240' in program for (string i = H; i < HELLO; i++) { ^ /usercode/file.cpp:5:26: error: stray '\302' in program for (string i = H; i < HELLO; i++) { ^ /usercode/file.cpp:5:27: error: stray '\240' in program for (string i = H; i < HELLO; i++) { ^ /usercode/file.cpp:6:1: error: stray '\302' in program   if (i == HELLO) { ^ /usercode/file.cpp:6:2: error: stray '\240' in program   if (i == HELLO) { ^ /usercode/file.cpp:6:3: error: stray '\302' in program   if (i == HELLO) { ^ /usercode/file.cpp:6:4: error: stray '\240' in program   if (i == HELLO) { ^ /usercode/file.cpp:6:7: error: stray '\302' in program   if (i == HELLO) { ^ /usercode/file.cpp:6:8: error: stray '\240' in program   if (i == HELLO) { ^ /usercode/file.cpp:6:14: error: stray '\302' in program   if (i == HELLO) { ^ /usercode/file.cpp:6:15: error: stray '\240' in program   if (i == HELLO) { ^ /usercode/file.cpp:7:1: error: stray '\302' in program     break; ^ /usercode/file.cpp:7:2: error: stray '\240' in program     break; ^ /usercode/file.cpp:7:3: error: stray '\302' in program     break; ^ /usercode/file.cpp:7:4: error: stray '\240' in program     break; ^ /usercode/file.cpp:7:5: error: stray '\302' in program     break; ^ /usercode/file.cpp:7:6: error: stray '\240' in program     break; ^ /usercode/file.cpp:7:7: error: stray '\302' in program     break; ^ /usercode/file.cpp:7:8: error: stray '\240' in program     break; ^ /usercode/file.cpp:8:1: error: stray '\302' in program   } ^ /usercode/file.cpp:8:2: error: stray '\240' in program   } ^ /usercode/file.cpp:9:1: error: stray '\302' in program   cout << i << "\n"; ^ /usercode/file.cpp:9:2: error: stray '\240' in program   cout << i << "\n"; ^ /usercode/file.cpp:9:16: error: stray '\302' in program   cout << i << "\n"; ^ /usercode/file.cpp:9:17: error: stray '\240' in program   cout << i << "\n"; ^ /usercode/file.cpp:10:2: error: stray '\302' in program }  ^ /usercode/file.cpp:10:3: error: stray '\240' in program }  ^ /usercode/file.cpp:1:1: error: 'include' does not name a type include <iostream> ^~~~~~~ /usercode/file.cpp: In function 'int main()': /usercode/file.cpp:5:7: error: 'string' was not declared in this scope for (string i = H; i < HELLO; i++) { ^~~~~~ /usercode/file.cpp:5:7: note: suggested alternative: 'struct' for (string i = H; i < HELLO; i++) { ^~~~~~ struct /usercode/file.cpp:5:23: error: 'i' was not declared in this scope for (string i = H; i < HELLO; i++) { ^ /usercode/file.cpp:5:28: error: 'HELLO' was not declared in this scope for (string i = H; i < HELLO; i++) { ^~~~~ /usercode/file.cpp:9:4: error: 'cout' was not declared in this scope   cout << i << "\n"; ^~~~

artemetra 🇺🇦 [less active]
i++ is not defined for std::string

using namespace std in the top of the code The problem is another

#include <iostream> #include <string> using namespace std; void print(const string text) { for (int i(0); i < text.size(); i++) { for (int j(0); j <= i; j++) cout << text.at(j); cout << '\n'; } } int main() { print("HELLO"); return 0; }

Похожие вопросы

Обсуждают сегодня

А чем вам питонисты не угодили?😂
.
79
всем доброго времени суток! имею вопрос: как понять ТОЧНО, что на нексус производится атака или он перегружен? исходные данные: - Nexus OSS 3.67.1-01 на OrientDB - Total co...
Michael Kostelcev
11
Всем привет, написал код ниже, но он выдает сегфолт, в чем причина? #include <stdio.h> #include <stdlib.h> #include <string.h> struct product { char *name; float price; };...
buzz базз
75
or any website to buy prepaid card with xmr that's not trocador that's down?
Umbrella Party Partner
18
Hi, I can't understand promises in JavaScript and what we should use them for (maybe the teacher didn't teach well XD). Do you have a solution for this? And are promises used...
A
29
Ещё такой вопрос. Мне необходимо хранить пароль пользователя локально. Для этого планирую использовать ini файл. Это для автозаполнения полей логин и пароль при авторизации. Е...
Евгений
19
Добрый день, LO Writer, проблема с нумерацией таблиц (вставка названия). У меня два стиля нумерованных списка, один для основного текста (вида 1.1.1) другой доя приложений (ви...
Виктор
6
My assets the Oceans at Binance, its displaying passive and no automatically convert, this situation will change?
Nationalizze
8
Xem delist ho rha hai agr naa bhechu toh kya hoga after 1 july?
ABHI
27
Ты просто гитлеровскую эстетику плохо понимаешь. Он же всё под Цезаря делал. А это как бы запрещённый приём в политике. Пиджаки они зачем все носят? Чтобы показать что они тип...
Ivan Kropotkin
4
Карта сайта