Weird Problem

This is a discussion on Weird Problem within the C++ Programming forums, part of the General Programming Boards category; Anyone see anything strange with this code? I'm basicly just setting up how I want it to look on the ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    38

    Weird Problem

    Anyone see anything strange with this code? I'm basicly just setting up how I want it to look on the screen and for some reason the only one it goes through is strName, the rest skips.....?


    Code:
    #include "stdafx.h"
    #using <mscorlib.dll>
    #include <tchar.h>
    #include <stdlib.h>
    #include <iostream>
    #include <conio.h> 
    using namespace std;
    using namespace System;
    #include <stdlib.h>
    #include <cstring>
    #include <iomanip>
    
    int _tmain()
    {
        char strName; 
    	char strNameA; 
    	char strName3; 
    	char strName4;
    	char strName5;
        
        cout << "Alphabetical Order System \n\n\n";
    
    	cout << "Enter Name # 1: ";
    	cin >> strName;
    	cout << "\n";
    
    	cout << "Enter Name # 2: ";
    	cin >> strNameA;
    	cout << "\n";
    	
    	cout << "Enter Name # 3: ";
    	cin >> strName3;
    	cout << "\n";
    	
    	cout << "Enter Name # 4: ";
    	cin >> strName4;
    	cout << "\n";
    	
    	cout << "Enter Name # 5: ";
    	cin >> strName5;
    	cout << "\n";
    
    
    	return 0;
    }

  2. #2
    Registered User
    Join Date
    Jun 2004
    Posts
    52
    Um I dont think its wrong cause I have seen it before but _t before main.........is that supposed to be there and if yes what does it mean or do?

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    38
    i'm not sure, it was auto generated by visual studio
    ....console app

  4. #4
    Registered User
    Join Date
    Jun 2004
    Posts
    52
    I also looks like you have alot of unused header files. Plus I believe <iomanip> needs to be <iomanip.h> and <cstring> should be <cstring.h> although that could be just somthing your compiler accepts......

  5. #5
    Registered User
    Join Date
    Sep 2004
    Posts
    38
    I excluded all the headers I wasn't using at the moment, those three were a must, cause it crashed otherwise, so I know its not a header issue now.

    also is that now how you use a string?

    Code:
    // This is the main project file for VC++ application project 
    // generated using an Application Wizard.
    
    //#include <iomanip>
    //#using <mscorlib.dll>
    //#include <tchar.h>
    //#include <stdlib.h>
    //#include <conio.h>
    //using namespace System;
    //#include <stdlib.h>
    //#include <cstring>
    #include "stdafx.h"
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    main()
    {
    	String* strName; //<-----------------------Wont work
    	double strNameA; 
    	double strName3; 
    	double strName4;
    	double strName5;
        
        cout << "Alphabetical Order System \n\n\n";
    
    	cout << "Enter Name # 1: ";
    	cin >> strName;
    	cout << "\n";
    
    	cout << "Enter Name # 2: ";
    	cin >> strNameA;
    	cout << "\n";
    	
    	cout << "Enter Name # 3: ";
    	cin >> strName3;
    	cout << "\n";
    	
    	cout << "Enter Name # 4: ";
    	cin >> strName4;
    	cout << "\n";
    	
    	cout << "Enter Name # 5: ";
    	cin >> strName5;
    	cout << "\n";
    
    
    	return 0;
    }
    Last edited by Xeavor; 11-20-2004 at 09:38 AM.

  6. #6
    Registered User
    Join Date
    Jun 2004
    Posts
    52
    Are you writing in C or something??? dont you need .h after header files? And I dont know aobut your pointer mess up cause I use reference.......I dont even see the point of pointers nemore but o well whatever floats your boat. Cept in Java...cause you cant pass by reference....

    -Edit
    I know poeple dont like it but I could put an edit for your program up that uses apstring if you wanted to. Just a suggestion.
    Last edited by Siggy; 11-20-2004 at 09:41 AM.

  7. #7
    Registered User
    Join Date
    Sep 2004
    Posts
    38
    c++ but if I add the .h to #include <iostream>
    #include <string> it crashes.

  8. #8
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    NO! C files require the *.h! In the new C++ standard, you use namespace std (as Xeavor has done), you remove the .h extension from header files, and you precede standard C header files with 'c'.

  9. #9
    Registered User
    Join Date
    Sep 2004
    Posts
    38
    lol, well guess the *string was the problem....thought i needed that...but oh well. Guess its without it. It works now.

    Code:
    // This is the main project file for VC++ application project 
    // generated using an Application Wizard.
    
    //#include <iomanip>
    //#using <mscorlib.dll>
    //#include <tchar.h>
    //#include <stdlib.h>
    //#include <conio.h>
    //using namespace System;
    //#include <stdlib.h>
    //#include <cstring>
    #include "stdafx.h"
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    main()
    {
    	string strName; 
    	string strNameA; 
    	string strName3; 
    	string strName4;
    	string strName5;
        
        cout << "Alphabetical Order System \n\n\n";
    
    	cout << "Enter Name # 1: ";
    	cin >> strName;
    	cout << "\n";
    
    	cout << "Enter Name # 2: ";
    	cin >> strNameA;
    	cout << "\n";
    	
    	cout << "Enter Name # 3: ";
    	cin >> strName3;
    	cout << "\n";
    	
    	cout << "Enter Name # 4: ";
    	cin >> strName4;
    	cout << "\n";
    	
    	cout << "Enter Name # 5: ";
    	cin >> strName5;
    	cout << "\n";
    
    
    	return 0;
    }

  10. #10
    Registered User
    Join Date
    Jun 2004
    Posts
    52
    If you have ne more questions dont hesitate to ask..

  11. #11
    Registered User
    Join Date
    Sep 2004
    Posts
    38
    Glade you asked heh, If I wanted to sort the names entered into this, What would be the most simple way.

  12. #12
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    A simple way would be to assign each name an array of numbers. In each element of that array, you would have a number corresponding to the letter. A = 1, Z = 26, etc... Then you can use a sorting algorithm (search the boards or look at AIHorizon.com) to arrange them by first letter, then second letter, etc...

  13. #13
    Registered User
    Join Date
    Sep 2004
    Posts
    38
    yeah I looked over that web page, arrays are confusing to me for some reason, or maybe I'm just not looking at it right.

  14. #14
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Sorting algorithms are complex. Perhaps this project is best left until you have a firm grasp on the following topics:

    - Arrays
    - Loops
    - Data types and ASCII values (or something similar)

  15. #15
    Registered User
    Join Date
    Sep 2004
    Posts
    38
    ok thanks for your help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Weird Problem With Pointer
    By DarkDot in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2007, 07:50 PM
  2. Weird problem on '02 3.4L V6 auto
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 01-11-2006, 11:05 PM
  3. Really Weird itoa Problem
    By Grantyt3 in forum C++ Programming
    Replies: 8
    Last Post: 12-19-2005, 11:44 PM
  4. Replies: 6
    Last Post: 05-12-2005, 03:39 AM
  5. Weird class problem!
    By aker_y3k in forum C++ Programming
    Replies: 2
    Last Post: 09-25-2002, 06:12 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21