4 Replies - 821 Views - Last Post: 08 September 2012 - 05:19 PM Rate Topic: -----

#1 Prdmama  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 26-November 11

Basic User Interface Program in C++

Posted 08 September 2012 - 01:56 PM

Ok I having a LINK error at the end of a program I am writing for school. This is my first coding class in about two years and I'm a bit out of touch...ok a lot out of touch so please be kind. The purpose of the program is to have the user input some basic data as a string and then the data is converted. The errors are the LNK 2019 and 1120 variety. Here is the basic gist of what I'm supposed to be doing, followed by what I have written.

Program Description: Basic User Interface
This program creates the basic user interface code that can be used in the following week’s iLab
assignments. The assignment will help you get started using the programming environment and some
practice with coding. You will also be able to re-use much, if not all, of the code in later assignments.
In this program, you will create the following methods:
1. DisplayApplicationInformation, which will provide the program user some basic information
about the program.
2. DisplayDivider, which will provide a meaningful output separator between different sections of
the program output.
3. GetInput, which is a generalized function that will prompt the user for a specific type of
information, then return the string representation of the user input.
4. TerminateApplication, which provides a program termination message and then terminates the
application.
Using these methods, you will construct a program that prompts the user for the following:
1. Your name, which will be a string data type
2. Your age, which will be an integer data type
3. The gas mileage for your car, which will be a double data type
4. Display the collected information
Also, note that the program should contain a well document program header.
Pseudocode
//Program Header
//Program Name: Basic User Interface
//Programmer: Your Name
//CIS247, Week 1 Lab
//Program Description: PROVIDE A DESCRIPTITON OF THE PROGRAM
Start main
//declare variables
input as string
name as string
age as integer
mileage as double
call DisplayApplicationInformation
call DisplayDivider(“Start Program”)
call DisplayDivider(“Get Name”)
set name = GetInput(“Your Name”)
display “Your name is: “ + name
call DisplayDivider(“Get Age”)
set input = GetInput(“Your Age”)
set age = convert input to integer
display “Your age is: “ + age
call DisplayDivider(“Get Mileage”)
set input = GetInput(“Gas Mileage”)
set mileage = convert input to double
//display mileage to 2 decimal places
display “Your car MPG is: “ + mileage
call TerminateApplication
end main program
procedure DisplayApplicationInformation
display “Welcome the Basic User Interface Program”
display “CIS247, Week 1 Lab”
display “Name: YOUR NAME”
display “This program accepts user input as a string, then makes the appropriate data conversion”
end procedure
procedure DisplayDivider(string outputTitle)
display “**************** “ + outputTitle + “****************”
end procedure
function GetInput(string inputType) as string
strInput as string
display “Enter the “ + inputType
get strInput
return strInput
end function
procedure TerminateApplication
display “Thank you for using the Basic User Interface program”
exit application
end procedure

//Program Header
//Program Name: Basic User Interface
//Programmer: 
//CIS247, Week 1 Lab
//Program Description: Have User Input Basic Data and Have the Program Display it With Dividers

#include <iostream>
#include <string>

using namespace std;

void DisplayApplicationInformation();
void DisplayDivider(string message);
string GetInput(string message);
void TerminateApplication();

int main()
{
	string name;
	string input;
	int age;
	double mileage;
	
	DisplayApplicationInformation();
	DisplayDivider("Start Program");

	DisplayDivider("Get Name");
	name = GetInput("Your Name");
	cout << "Your name is " << name <<endl;
	
	DisplayDivider("Get Age");
	input = GetInput("Your Age");
	age = atoi(input.c_str());
	cout << "Your age is " << age <<endl;
	
	DisplayDivider("Get Mileage");
	input = GetInput("Your mileage");
	mileage = atof(input.c_str());
	cout << "Your car MPG is " << mileage <<endl;
	
	TerminateApplication();
 }

 void DisplayApplicationInformation()
 {
	 cout << "Welcome the Basic User Interface Program " << endl;
	 cout << "CIS247, Week 1 Lab" << endl;
	 cout << "Name: YOUR NAME" << endl;
	 cout << "This program accepts user input as a string, then makes the appropriate data conversion" << endl;
 }

 void DisplayDivider(string outputTile)
 {
	 cout << "**********************" << outputTile << "******************" << endl;
 }

 string GetInput(string inputType)
 {
	 string input;
	 cout << "Enter the "<< inputType <<": ";
	 cin >> input;
	 return input;
 }

 void TerminateApplication()
 {
	 cout << "Thank You For Using the Basic User Interface Program";
 }


Is This A Good Question/Topic? 0
  • +

Replies To: Basic User Interface Program in C++

#2 jimblumberg  Icon User is offline

  • member icon

Reputation: 3055
  • View blog
  • Posts: 9,292
  • Joined: 25-December 09

Re: Basic User Interface Program in C++

Posted 08 September 2012 - 01:59 PM

If you are getting compile/link errors post the complete error messages exactly as they appear in your development environment.

Jim
Was This Post Helpful? 0
  • +
  • -

#3 Prdmama  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 26-November 11

Re: Basic User Interface Program in C++

Posted 08 September 2012 - 02:21 PM

View Postjimblumberg, on 08 September 2012 - 01:59 PM, said:

If you are getting compile/link errors post the complete error messages exactly as they appear in your development environment.

Jim


Thanks for replying Jim. I really want to be able not only to fix what I've done wrong but understand it too. Here is what it says when I try to build.

MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
1>C:\Users\Lexi\documents\visual studio 2010\Projects\CIS247C_WK1_Lab_Stephens\Debug\CIS247C_WK1_Lab_Stephens.exe : fatal error LNK1120: 1 unresolved externals
1>
1>Build FAILED
Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg  Icon User is offline

  • member icon

Reputation: 3055
  • View blog
  • Posts: 9,292
  • Joined: 25-December 09

Re: Basic User Interface Program in C++

Posted 08 September 2012 - 02:34 PM

This error message is telling you that your project is setup to compile a Windows program and the linker can't seem to find a WinMain() function. This problem is being caused because you are not trying to write a Windows program, but a command line program. You need to change your project settings so you are not compiling for a Windows program. Check the FAQ, I believe that there is an entry about this problem and how exactly to correct the issue.

Jim
Was This Post Helpful? 0
  • +
  • -

#5 Prdmama  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 26-November 11

Re: Basic User Interface Program in C++

Posted 08 September 2012 - 05:19 PM

View Postjimblumberg, on 08 September 2012 - 02:34 PM, said:

This error message is telling you that your project is setup to compile a Windows program and the linker can't seem to find a WinMain() function. This problem is being caused because you are not trying to write a Windows program, but a command line program. You need to change your project settings so you are not compiling for a Windows program. Check the FAQ, I believe that there is an entry about this problem and how exactly to correct the issue.

Jim


Thank you so much! That certainly a DOH moment. All fixed.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1