[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Display no value

Posted on 2011-05-01
10
Medium Priority
?
323 Views
Last Modified: 2013-12-16
Hi guys: Can any one please tell me what i make mistake as the program runs but it dont display the age. Thanks.


#include <iostream>
using namespace test;

void getAge(int years);

int main()
{
      int age = 0;
      getAge(age);
      cout << "You are " << age << " years old." << endl;

      system("pause");
      return 0;
}
void getAge(int years)
{  
      cout << "Enter an age: ";
      cin >> years;
}
0
Comment
Question by:mustish1
  • 4
  • 2
  • 2
  • +1
10 Comments
 
LVL 14

Assisted Solution

by:systan
systan earned 400 total points
ID: 35501195
void getAge(ref int years) ?
0
 
LVL 14

Expert Comment

by:systan
ID: 35501200
or
void getAge(out int years)
0
 
LVL 17

Assisted Solution

by:Daniel Reynolds
Daniel Reynolds earned 400 total points
ID: 35501204
just change the scope of the age variable as follows
Question: Hi guys: Can any one please tell me what i make mistake as the program runs but it dont display the age. Thanks.


#include <iostream>
using namespace test;

void getAge();
private int age =0;
int main()
{
     
      getAge();
      cout << "You are " << age << " years old." << endl;

      system("pause");
      return 0;
}
void getAge(i)
{  
      cout << "Enter an age: ";
      cin >> age;
}
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 29

Expert Comment

by:Paul Jackson
ID: 35501216
#include <iostream>
using namespace test;

int getAge(int years);

int main()
{
      int age = 0;
      age = getAge();
      cout << "You are " << age << " years old." << endl;

      system("pause");
      return 0;
}
int getAge()
{  
      int inputage = 0;
      cout << "Enter an age: ";
      cin >> inputage;
      return(inputage);
}
0
 

Author Comment

by:mustish1
ID: 35501230
C:\Documents and Settings\Kathy\My Documents\test.cpp: In function `int main()':
C:\Documents and Settings\Kathy\My Documents\test.cpp:4: error: too few arguments to function `int getAge(int)'
C:\Documents and Settings\Kathy\My Documents\test.cpp:9: error: at this point in file

Execution terminated


#include <iostream>
using namespace test;

int getAge(int years);

int main()
{
      int age = 0;
      age = getAge();
      cout << "You are " << age << " years old." << endl;

      system("pause");
      return 0;
}
int getAge()
{  
      int inputage = 0;
      cout << "Enter an age: ";
      cin >> inputage;
      return(inputage);
}
0
 

Author Comment

by:mustish1
ID: 35501242
C:\Documents and Settings\Kathy\My Documents\test.cpp:4: error: conflicts with previous declaration `void getAge()'
C:\Documents and Settings\Kathy\My Documents\test.cpp:15: error: `i' was not declared in this scope
C:\Documents and Settings\Kathy\My Documents\test.cpp:16: error: expected `,' or `;' before '{' token

Execution terminated

#include <iostream>
using namespace test;

void getAge();
private int age =0;
int main()
{
     
      getAge();
      cout << "You are " << age << " years old." << endl;

      system("pause");
      return 0;
}
void getAge(i)
{  
      cout << "Enter an age: ";
      cin >> age;
}
0
 

Author Comment

by:mustish1
ID: 35501251
#include <iostream>
using namespace test;

void getAge(int years);

int main()
{
      int age = 0;
      getAge(age);
      cout << "You are " << age << " years old." << endl;

      system("pause");
      return 0;
}
void getAge(ref int years)
{  
      cout << "Enter an age: ";
      cin >> years;
}



Compiler: Default compiler
Executing  g++.exe...
g++.exe "C:\Documents and Settings\Kathy\My Documents\test.cpp" -o "C:\Documents and Settings\Kathy\My Documents\test.exe"    -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include"  -I"C:\Dev-Cpp\include\c++\3.4.2\backward"  -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32"  -I"C:\Dev-Cpp\include\c++\3.4.2"  -I"C:\Dev-Cpp\include"   -L"C:\Dev-Cpp\lib"
C:\Documents and Settings\Kathy\My Documents\test.cpp:15: error: variable or field `getAge' declared void
C:\Documents and Settings\Kathy\My Documents\test.cpp:15: error: `int getAge' redeclared as different kind of symbol
C:\Documents and Settings\Kathy\My Documents\test.cpp:4: error: previous declaration of `void getAge(int)'
C:\Documents and Settings\Kathy\My Documents\test.cpp:15: error: declaration of `int getAge'
C:\Documents and Settings\Kathy\My Documents\test.cpp:4: error: conflicts with previous declaration `void getAge(int)'
C:\Documents and Settings\Kathy\My Documents\test.cpp:15: error: `ref' was not declared in this scope
C:\Documents and Settings\Kathy\My Documents\test.cpp:16: error: expected `,' or `;' before '{' token

Execution terminated
0
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 1200 total points
ID: 35501252
forgot to take parameter out of the function header :

#include <iostream>
using namespace test;

int getAge();

int main()
{
      int age = 0;
      age = getAge();
      cout << "You are " << age << " years old." << endl;

      system("pause");
      return 0;
}
int getAge()
{  
      int inputage = 0;
      cout << "Enter an age: ";
      cin >> inputage;
      return(inputage);
}
0
 

Author Closing Comment

by:mustish1
ID: 35501266
Thanks a lot.
0
 
LVL 17

Expert Comment

by:Daniel Reynolds
ID: 35501268
sorry, left the letter 'i' in the getAge() definition. remove it and it should work.

#include <iostream>
using namespace test;

void getAge();
private int age =0;
int main()
{
     
      getAge();
      cout << "You are " << age << " years old." << endl;

      system("pause");
      return 0;
}
void getAge()
{  
      cout << "Enter an age: ";
      cin >> age;
}
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Screencast - Getting to Know the Pipeline
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question