为什么goto语句总是返回不正确?

[复制链接]
查看11 | 回复3 | 2008-11-3 09:39:20 | 显示全部楼层 |阅读模式
#include"stdio.h"
main()
{
struct student
{
char name[20];
char sex[2];
int age;
float score;
}stud;

begin:printf("请输入姓名:");
gets(stud.name);
printf("请输入性别:");
gets(stud.sex);
printf("请输入年龄:");
scanf("%d",&stud.age);
printf("请输入成绩:");
scanf("%f",&stud.score);
printf("\n姓名:%s\n性别:%s\n年龄:%d\n成绩:%.2f\n",stud.name,

stud.sex,stud.age,stud.score);
goto begin;
}

回复

使用道具 举报

千问 | 2008-11-3 09:39:20 | 显示全部楼层
总算给你找到毛病了,绝对返回正确。兄弟提醒你:结构化程序设计方法主张限制使用goto语句,因为滥用goto语句将使程序流程无规律、可读性差。但也不是绝对禁止使用goto语句。#include"stdio.h" void main() { struct student{ char name[20]; char sex[2]; int age; float score;}stud; loop:printf("请输入姓名:");getchar();gets(stud.name);
printf("请输入性别:");getchar();...
回复

使用道具 举报

千问 | 2008-11-3 09:39:20 | 显示全部楼层
#include"stdio.h" main() {struct student { char name[20]; char sex[2]; int age; float score; }stud;begin: printf("Please input name:\n");scanf("%s",&stud.na...
回复

使用道具 举报

千问 | 2008-11-3 09:39:20 | 显示全部楼层
begin:printf("请输入姓名:");gets(stud.name);printf("请输入性别:");gets(stud.sex);printf("请输入年龄:");scanf("%d",&stud.age);printf("请输入成绩:");scanf("%f",&stud.score);printf("\n姓名:...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行