【问题标题】:Scope not defined c++ need int inout [closed]范围未定义 C++ 需要 int inout [关闭]
【发布时间】:2015-03-22 00:08:40
【问题描述】:
#include <iostream>
#include <stdio.h>

int main(void)
{
   printf("Hello, CS 101! \n");

   int age{
     printf("How old are you? \n")
    };
   printf("OK, you are",scanf(%i,&age),"years old.");


   return 0;
}

我们的任务需要使用 scanf 和 printf 来找出用户的年龄,然后打印一个声明他们的年龄。

我们的教授没有复习语法,而是在课堂上给了我们代码,但我离董事会太远了,看不到。这是我自己得到的,但是我没有找到好的c++编码资源。

我得到了未定义的错误范围,有人可以帮助我吗?此外,如果有人有从头开始学习的良好资源,那就太好了。这是我第一次写代码,谢谢。

【问题讨论】:

  • 你在学习 C 还是 C++?
  • 年龄应该是函数还是变量?
  • 你想从头开始学习,因为你的座位位置?请和你的教授谈谈这个问题。另外,C 不是 C++ 不是 C,而您正在编写 C。
  • @Botan "但是我还没有找到好的 c++ 编码资源" 说真的?你的教科书呢?

标签: c++ scope int printf scanf


【解决方案1】:

我修复了你的代码。希望这是你所追求的:

#include <iostream>
#include <stdio.h>

int main(void)
{
   printf("Hello, CS 101! \n");


   // declare age as int
   int age;

   // ask for age 
   printf("How old are you? \n");

   // get user input into age
   scanf("%d", &age);

   // display entered age
   printf("OK, you are %d years old.\n", age);

   return 0;
}

【讨论】:

  • 考虑到 OP 是初学者,如果您解释一下您的更改会更好。
  • @Borgleader 我添加了 cmets,解释发生了什么。
猜你喜欢
  • 1970-01-01
  • 2021-05-18
  • 1970-01-01
  • 2015-01-06
  • 1970-01-01
  • 2021-08-06
  • 1970-01-01
  • 2012-03-18
  • 2022-01-25
相关资源
最近更新 更多