qq_73763697 2022-12-09 20:17 采纳率: 100%
浏览 58
已结题

C语言编写小熊时钟,fatal error C1017: 无效的整数常量表达式

用这个代码运行不出结果,错误如下,该怎么解决

img

#include<iostream>
#include<math.h>
#include<time.h>
#include<Windows.h>
#include <wtypes.h>
#include <conio.h>
#include <graphics.h>

#define PI 3.1415926
#define ESC 0x011b
int s0 = -1, m0 = -1, h0 = -1;
int main()
{
    int key, i = 3;
    char H[10];
    float n;
    HDC hdc = GetDC(GetConsoleWindow());
    HPEN hpen = CreatePen(PS_SOLID, 1, RGB(0, 0, 225));
    SelectObject(hdc, hpen);
    Ellipse(hdc, 380, 150, 430, 200);
    Ellipse(hdc, 210, 150, 260, 200);
    Ellipse(hdc, 295, 225, 345, 275);
    Ellipse(hdc, 297, 227, 343, 273);
    for (n = 0; n <= 2 * PI; n += PI / 30)
    {
        MoveToEx(hdc, 320, 240, NULL);
        LineTo(hdc, 320 + 80 * cos(-n), 240 + 80 * sin(-n));
    }
    for (n = 0; n <= 2 * PI; n += PI / 6)
    {
        itoa(i, H, 10);
        TextOutA(hdc, 317 + 73 * cos(-n), 237 + 73 * sin(-n), H, strlen(H));
        i--;
        if (i < 1)
            i += 12;
    }
    while (!kbhit())
    {
        timer();
        Sleep(1000);
    }
    key = getch();
    if (key == ESC)
    {
        ReleaseDC(GetConsoleWindow(), hdc);
        exit(0);
    }
    return 0;
}
void timer()
{
    struct tm* when;
    float s, m1, h1;
    int h, m;
    time_t now;
    time(&now);
    when = localtime(&now);
    h = when->tm_hour;
    m = when->tm_min;
    s = when->tm_sec;
    h1 = (h + (m * 60 + s) / 3600) * PI / 6 - PI / 2;
    m1 = (m + s / 60) * (PI / 30) - PI / 2;
    if (s0 != (-1) && m0 != (-1) && h0 != (-1))
    {
        setcolor(0);
        line(320, 240, 320 + 45 * cos(h0), 240 + 45 * sin(h0));
        line(320, 240, 320 + 55 * cos(m0), 240 + 55 * sin(m0));
        line(320, 240, 320 + 65 * cos(s0), 240 + 65 * sin(s0));
    }
    setcolor(15);
    line(320, 240, 320 + 45 * cos(h1), 240 + 45 * sin(h1));
    line(320, 240, 320 + 55 * cos(m1), 240 + 55 * sin(m1));
    setcolor(4);
    line(320, 240, 320 + 65 * cos(s * (PI / 30) - PI / 2), 240 + 65 * sin(s * (PI / 30) - PI / 2));
    s0 = s * (PI / 30) - PI / 2;
    m0 = m1;
    h0 = h1;
}
  • 写回答

1条回答 默认 最新

  • 浪客 2022-12-09 20:53
    关注

    #if后面缺个(

    修改了下你的,你的代码API和easyx混用,改成纯eaxyx了。

    #include <math.h>
    #include <time.h>
    #include <conio.h>
    #include <graphics.h>
    
    void timer();
    
    #define PI 3.1415926
    #define ESC 0x011b
    int s0 = -1, m0 = -1, h0 = -1;
    int main()
    {
        int key, i = 3;
        char H[10];
        float n;
        initgraph(640, 480); //
    
        //  HWND hwnd = GetConsoleWindow(); //
        // HDC hdc = GetDC(GetConsoleWindow());
        // HDC hdc = GetDC(hwnd); //
        // HPEN hpen = CreatePen(PS_SOLID, 1, RGB(0, 0, 225));
    
        // SelectObject(hdc, hpen);
    
        setbkcolor(BLACK);                  // 背景颜色
        setbkmode(TRANSPARENT);              // 文字背景透明
        settextcolor(RGB(255, 255, 255)); // 文字颜色
    
        while (1) // while (!kbhit())
        {
            setcolor(WHITE);
            fillellipse(380, 150, 430, 200);
            fillellipse(210, 150, 260, 200);
            fillellipse(295, 225, 345, 275);
            fillellipse(297, 227, 343, 273);
    
            setcolor(RGB(0, 0, 225));
            for (n = 0; n <= 2 * PI; n += PI / 30)
            {
                // MoveToEx(hdc, 320, 240, NULL);
                line(320, 240, 320 + 80 * cos(-n), 240 + 80 * sin(-n)); //        LineTo(hdc, 320 + 80 * cos(-n), 240 + 80 * sin(-n));
            }
    
            setcolor(WHITE);
            for (n = 0; n <= 2 * PI; n += PI / 6)
            {
                itoa(i, H, 10);
                outtextxy(317 + 73 * cos(-n), 237 + 73 * sin(-n), H); //        TextOut(hdc, 317 + 73 * cos(-n), 237 + 73 * sin(-n), H, strlen(H));
                i--;
                if (i < 1)
                    i += 12;
            }
    
            timer();
            Sleep(1000);
            cleardevice(); // 刷新
    
            i = 3;
            if (kbhit())
            {
                key = getch();
                if (key == ESC)
                {
                    closegraph();
                    // ReleaseDC(GetConsoleWindow(), hdc);
                    // exit(0);
                }
            }
        }
    
        return 0;
    }
    void timer()
    {
        struct tm *when;
        float s, m1, h1;
        int h, m;
        time_t now;
        time(&now);
        when = localtime(&now);
        h = when->tm_hour;
        m = when->tm_min;
        s = when->tm_sec;
        h1 = (h + (m * 60 + s) / 3600) * PI / 6 - PI / 2;
        m1 = (m + s / 60) * (PI / 30) - PI / 2;
        // if (s0 != (-1) && m0 != (-1) && h0 != (-1))
        // {
        //     setcolor(0);
        //     line(320, 240, 320 + 45 * cos(h0), 240 + 45 * sin(h0));
        //     line(320, 240, 320 + 55 * cos(m0), 240 + 55 * sin(m0));
        //     line(320, 240, 320 + 65 * cos(s0), 240 + 65 * sin(s0));
        // }
    
        setcolor(RED);
        setlinestyle(PS_SOLID, 5);
        line(320, 240, 320 + 45 * cos(h1), 240 + 45 * sin(h1));
        line(320, 240, 320 + 55 * cos(m1), 240 + 55 * sin(m1));
    
        setcolor(YELLOW);
        setlinestyle(PS_SOLID, 1);
        line(320, 240, 320 + 65 * cos(s * (PI / 30) - PI / 2), 240 + 65 * sin(s * (PI / 30) - PI / 2));
    
        s0 = s * (PI / 30) - PI / 2;
        m0 = m1;
        h0 = h1;
    }
    
    

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 12月19日
  • 已采纳回答 12月11日
  • 创建了问题 12月9日

悬赏问题

  • ¥15 maccms影视模板 制作影视网站失败 求
  • ¥15 stm32按键设置闹钟数进退位不正常
  • ¥15 三电平逆变器中点电位平衡问题
  • ¥20 这怎么写啊 java课设
  • ¥15 用C语言完成一个复杂的游戏
  • ¥15 如何批量更改很多个文件夹里的文件名中包含文件夹名?
  • ¥50 MTK手机模拟HID鼠标出现卡顿
  • ¥20 求下下面这个数据结构代码
  • ¥20 前端 二进制文件流图片转化异常
  • ¥15 github上的这个C语言项目如何跑起来