-
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");
}
-
try making it just
char letter;
-
i have...i still get a problem
-
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);
}
-
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!
-
yes i did that but it didnt work. Visual C++ said something about the != operator. I dont know, but i got it now. Thanks.
-
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.