counting

Solved
Last edited on
It’s generally considered kinda bratty to just post an entire program, and then not even post the error. That being said, we will help you, just try to remember that we aren’t just slaves to crawl through your code looking for any possible error on earth.
There is no compiler error. Although 20, 30, 40... print out as 29, 39, 49.......
How can i fix this error.
Hm... that is a strange one, Idk actually that’ll take a bit of thinking. It should be impossible, seeing as 20 mod 10 is most definitely 0. What was the entire input you had?
20 would output 20 shi jiu instead of 20 shi
But is 20 the num2, the num1...? See where I’m going with this? Lol.
Neither all numbers are stored in strings. The single digits are stored in ones and double digits are stored in tens.
There's a new program out called novel coronavirus that's started counting up to 150 million.
Somebody was upset - probably because they can't have bat soup and civet pudding with their supper any more. Too many of their aunties are dropping dead because their uncle thinks eating wild animals from wet markets gives him longer erections, now that the world is running out of rhinoceros horn powder.
Wow, way to make friends, againtry.

So, since I played with this on my own anyway...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Make sure to save as UTF-8, and on Windows, let your compiler know
// the input is UTF-8 and "chcp 65001" your console before running.

#include <iomanip>
#include <iostream>
#include <string>
#include <utility>

std::pair <std::string, std::string> numbers[] =
{
  { "一",  "yī"  },
  { "二",  "èr"  },
  { "三",  "sān" },
  { "四",  "sì"  },
  { "五",  "wǔ"  },
  { "六",  "liù" },
  { "七",  "qī"  },
  { "八",  "bā"  },
  { "九",  "jiǔ" },
  { "十",  "shí" },
};

std::string colors[] =
{
  "\033[93;40m",  // yellow on black
  "\033[94;40m",  // light blue on black
};

std::string mandarin_digits_1_99( int n )
{
  std::string result;
  if (n >= 20) result += (char)(n / 10);
  if (n >= 10) result += (char)10;
  if (n %  10) result += (char)(n % 10);
  return result;
}

void print( int n )
{
  std::string cjk, pinyin;
  int k = 0;
  for (char c : mandarin_digits_1_99( n ))
  {
    if (!pinyin.empty()) pinyin += " ";
    cjk    += numbers[ (int)c - 1 ].first;
    pinyin += numbers[ (int)c - 1 ].second;
    k      += 1;
  }
  while (k++ < 3) cjk += "  ";             // setw(manually) : CJK are double-wide characters
  std::cout
    << std::left       << colors[ n % 2 ]  // alternating line color
    << std::setw( 3 )  << n      << "   "  // western digits (3 digits wide)
    <<                    cjk    << "   "  // Chinese digits (3 digits wide --> 6 characters wide)
    << std::setw( 10 ) << pinyin << "\n";  // Romanization   (max 10 characters)
}

int main()
{
  for (int n = 1; n < 100; n++) print( n );
  std::cout << colors[ 0 ] << "100   一百     yì bǎi\033[0m\n";
}

Meh.
You’re absolutely right Duthomas wet markets don’t have friends. Saving face hasn’t worked so far in the Year of the Rat - or is it xi xing ping’s Year of the Bat?
Topic archived. No new replies allowed.