【无标题】求专家给看看,运行过程中总是出现从double到float的错误

此篇博客展示了如何利用C++编程语言,结合数学公式和随机性,创建动态的点阵图案。通过控制变量U和V,程序在屏幕上生成复杂而有序的几何形状,涉及颜色变化和字符显示。值得注意的是,代码中存在一些警告和错误,提示开发者注意类型转换和语法问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include<stdio.h>
#include<math.h>
#include<windows.h>
#include<time.h>
#define U 0.1
#define V 0.053
void SetColor(unsigned short ForeColor, unsigned short BackGroundColor)    /*定义两个变量背景色和主颜色*/
{
	HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);/**/
	SetConsoleTextAttribute(hCon, (ForeColor) | (BackGroundColor) * 16);
}
int main()
{
	int i, s = 0, t, a = 10, b = 11, c = 12,d = 13, e = 14;     /*定义行*/
	int z[] = { 32,32,206,210,207,178,187,182,196,227,33,32,32 };   /*定义一个字符变量*/
	float x, y;                                                 /*定义x,y变量*/
	srand(time(NULL));
	for (y = 1.3; y >= -1.1; y -= U)
	{
		for (x = -2; x < 1.4; x += V)
		{
			if (((x*x + y * y - 1)*(x*x + y * y - 1)*(x*x + y * y - 1) - x * x * y * y) <= 0);
			{
				if (y >= 1.3 - 10 * U || y <= 1.3 - 11 * U)
				{
					s++;
					if (s % 4 == 1)
					{
						SetColor(a, 0);
						printf("l");
					}
					if (s % 4 == 2)
					{
						SetColor(e, 0);
						printf("o");
					}
					if (s % 4 == 3)
					{
						SetColor(c, 0);
						printf("v");
					}
					if (s % 4 == 0)
					{
						SetColor(d, 0);
						printf("e");
					}
					else
					{
						for (i = 0; i < 42; i++)
						{
							if (i <= 14 || i >= 28)
							{
								s++;
								if (s % 4 == 1)
								{
									SetColor(a, 0);
									printf("l");
								}
								if (s % 4 == 2)
								{
									SetColor(e, 0);
									printf("o");
								}
								if (s % 4 == 3)
								{
									SetColor(c, 0);
									printf("v");
								}
								if (s % 4 == 0)
								{
									SetColor(d, 0);
									printf("e");
								}
							}
							else
							{
								SetColor(b, 0);
								printf("%c", z[i - 15]);
								Sleep(50);
							}
						}
						break;
					}
				}
				else

					printf(" ");
				Sleep(1);
			}
			printf(" ");
		}
		printf("按任意键继续! ");
		getchar();
		while (1)
		{
			system("cls");
			t = a; a = b; b = c; c = d; d = e; e = t;  /*赋值*/
			for (y = 1.3; y >= -1; y -= U)
			{
				for (x = -2; x < 1.4; x += V)
				{
					if (((x*x + y * y - 1)*(x*x + y * y - 1)*(x*x + y * y - 1) - x * x * y * y) <= 0);
				}
				if (y >= 1.3 - 10 * U || y <= 1.3 - 11 * U)
				{
					s++;
					if (s % 4 == 1)
					{
						SetColor(a, 0);
						printf("l");
					}
					if (s % 4 == 2)
					{
						SetColor(e, 0);
						printf("o");
					}
					if (s % 4 == 3)
					{
						SetColor(c, 0);
						printf("v");
					}
					if (s % 4 == 0)
					{
						SetColor(d, 0);
						printf("e");
					}
				}
				else
				{
					for (i = 0; i < 42; i++)
					{
						if (i < 14 || i>28)
						{
							s++;
							if (s % 4 == 1)
							{
								SetColor(a, 0);
								printf("l");
							}
							if (s % 4 == 2)
							{
								SetColor(e, 0);
								printf("o");
							}
							if (s % 4 == 3)
							{
								SetColor(c, 0);
								printf("v");
							}
							if (s % 4 == 0)
							{
								SetColor(d, 0);
								printf("e");
							}
						}
						else
						{
							SetColor(e, 0);
							printf("%c", z[i - 15]);
						}
					}
					break;
				}
			}
        else
			printf(" ");
		}
		printf("\n");
	}
			Sleep(1000);
			system("cls");
	

1>------ 已启动生成: 项目: Project31, 配置: Debug Win32 ------
1>源.cpp
1>c:\users\23967\source\repos\project31\project31\源.cpp(17): warning C4244: “参数”: 从“time_t”转换到“unsigned int”,可能丢失数据
1>c:\users\23967\source\repos\project31\project31\源.cpp(18): warning C4305: “=”: 从“double”到“float”截断
1>c:\users\23967\source\repos\project31\project31\源.cpp(18): warning C4305: “-=”: 从“double”到“float”截断
1>c:\users\23967\source\repos\project31\project31\源.cpp(20): warning C4305: “+=”: 从“double”到“float”截断
1>c:\users\23967\source\repos\project31\project31\源.cpp(98): warning C4305: “=”: 从“double”到“float”截断
1>c:\users\23967\source\repos\project31\project31\源.cpp(98): warning C4305: “-=”: 从“double”到“float”截断
1>c:\users\23967\source\repos\project31\project31\源.cpp(100): warning C4305: “+=”: 从“double”到“float”截断
1>c:\users\23967\source\repos\project31\project31\源.cpp(165): error C2181: 没有匹配 if 的非法 else
1>c:\users\23967\source\repos\project31\project31\源.cpp(13): fatal error C1075: “{”: 未找到匹配令牌
1>已完成生成项目“Project31.vcxproj”的操作 - 失败。
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值