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

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 我想在一个软件里添加一个优惠弹窗,应该怎么写代码
  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流