Results 1 to 7 of 7

Thread: help!

  1. #1

    Thread Starter
    Frenzied Member SomethinCool's Avatar
    Join Date
    Jan 2001
    Location
    Malvern, PA
    Posts
    1,407

    help!

    why doesnt this work:

    Code:
    #include "stdafx.h"
    #include "iostream"
    
    using namespace std;
    
    int main(int argc, char* argv[])
    {
    	int i;
    	char letter;
    	char option[2];
    	int x;
    	do
    	{
    		cout << "Enter a Number: ";
    		cin >> i;
    		letter = i;
    		cout << "\nNumber you entered: " << i;
    		cout << "\nEquivalent Letter: " << letter;
    		cout << "\nRestart from beginning? (Y for Yes, N for No): ";
    		cin >> option;
    		if(option == "N")
    		{
    			return 0;
    		}
    	}while(option != "N");
    	
    }

  2. #2
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    try making it just

    char letter;

  3. #3

    Thread Starter
    Frenzied Member SomethinCool's Avatar
    Join Date
    Jan 2001
    Location
    Malvern, PA
    Posts
    1,407
    i have...i still get a problem

  4. #4

    Thread Starter
    Frenzied Member SomethinCool's Avatar
    Join Date
    Jan 2001
    Location
    Malvern, PA
    Posts
    1,407
    i figured it out...all i needed was this:

    Code:
    #include "stdafx.h"
    #include "iostream"
    
    using namespace std;
    
    int main(int argc, char* argv[])
    {
    	int i;
    	char letter;
    	char option[2];
    	int x;
    	do
    	{
    		cout << "Enter a Number: ";
    		cin >> i;
    		letter = i;
    		cout << "\nNumber you entered: " << i;
    		cout << "\nEquivalent Letter: " << letter;
    		cout << "\nRestart from beginning? (Y for Yes, N for No): ";
    		cin >> option;
    	}while(int(option) != 78);
    	
    }

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    This does work????????
    VERY strange!

    The problem you have is the usual problem of C strings that so many newbies have. You can NOT use the == operator to compare strings!
    A method that surely works (your method seems like a miracle to me) is this: replace
    char option[2];
    with
    char option;
    and do this:
    while(option != 'N');
    This tests whether the character option contains the character N (note the single braces, it means you want the character, not the string)

    Always remember: it's character that counts!
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6

    Thread Starter
    Frenzied Member SomethinCool's Avatar
    Join Date
    Jan 2001
    Location
    Malvern, PA
    Posts
    1,407
    yes i did that but it didnt work. Visual C++ said something about the != operator. I dont know, but i got it now. Thanks.

  7. #7
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Code:
    #include "stdafx.h"
    #include "iostream"
    You shouldn't need stdafx.h, it's only there for VC++6's personal gratification...disable precompiled headers until you know what they are (under project settings).

    The "iostream" should be <iostream> since it's a system header.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width