473,395 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

C++ Error (NEED HELP!)

93 64KB
Hi again, X here

Yet again I have a problem with my learnig files...

error:

"Expected primary-expression before "char"" on line 17

My code for now:

Expand|Select|Wrap|Line Numbers
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <string>        //NOTE THIS ONE!!!!!!
  4.  
  5. using namespace std;
  6.  
  7. string String;
  8. char UserString[250];
  9. char inputAnswer[250];
  10.  
  11. int main()
  12. {
  13.     string String = "I AM A STRING!!!!!!";
  14.     cout << String << endl;
  15.     cout << "" << endl;
  16.     cout << "Please write a word... " << endl;
  17.     cin.getline(UserString, 250, "\n");
  18.     cout << "Did you type: " << endl;
  19.     cout << UserString << endl;
  20.     cout << "If so write 'Yes' if not write 'No' and press enter... " << endl;
  21.     cin >> inputAnswer;
  22.     if (bool inputAnswer = "yes" || "Yes")
  23.     {
  24.         cout << "Very well then... " << endl;
  25.         return false;
  26.     }
  27.     else
  28.     {
  29.         if (bool inputAnswer = "no" || "No")
  30.         {
  31.             cout << "Sorry! Contact programmer!" << endl;
  32.             return false;
  33.             };
  34.     };
  35.  
  36.     system("PAUSE");
  37.     return EXIT_SUCCESS;
  38. };
  39.  
  40.  
Some help is greatly appreciated...

X
Jul 6 '13 #1
5 1292
divideby0
131 128KB
why do you have semi-colons after some of the closing brackets? get rid of those. cin.getline should be '\n' and not "\n" as it's a single character.

I'm not really beyond the basics of cpp, but if you plan on using c-style string functions, you may need to include <cstring>.
Jul 7 '13 #2
weaknessforcats
9,208 Expert Mod 8TB
ER...

Expand|Select|Wrap|Line Numbers
  1. if (bool inputAnswer = "yes" || "Yes")
inputAnswer is a bool. "yes" and Yes" both exist and have addresses. The addresses are not zero. Therefore inputAnswer is always true.

Notice that this inputAnswer is not the same one defined earlier in the code.

What are you trying to do here?
Jul 7 '13 #3
Xillez
93 64KB
"yes" and "yes" is basicly the input from the person that uses the program...
Expand|Select|Wrap|Line Numbers
  1. if (bool inputAnswer = "yes" || "Yes")
  2.     {
  3.         cout << "Very well then... " << endl;
  4.         return false;
  5.     }
  6.     else
  7.     {
  8.         if (bool inputAnswer = "no" || "No")
  9.         {
  10.             cout << "Sorry! Contact programmer!" << endl;
  11.             return false;
  12.             }
  13.     }
  14.  
weaknessforcats...

The thing is basicly to check if the User typed "Yes", it will say "very well then... " and exit the program, if not it's gone return false and go to the other if statement with the "no" and so on...

I know. inputAnswer is not gone be defined until the user types "yes" or "no" and that data is gone be pushed in to inputAnswer. So should I move "char inputAnswer;" from a public variable to a local one?
Jul 7 '13 #4
divideby0
131 128KB
if you're looking to compare what the user types and gets stored the char version of inputAnswer, then use strcmp or strncmp.

Expand|Select|Wrap|Line Numbers
  1. if(strncmp(inputAnswer, "yes", 3) == 0 || strncmp(inputAnswer, "Yes", 3) == 0)
  2.    // user typed yes or Yes
  3.  
You've also got "YES", "YeS", "yES" etc. To get away from the cases, convert the string to one case or the other.

Expand|Select|Wrap|Line Numbers
  1. for(int i=0; (inputArray[i] = tolower(inputArray[i])) != '\0'; ++i){}
  2.  
  3. if(strncmp(inputAnswer, "yes", 3) == 0)
  4.    // user wants yes
  5.  
An easier way may be just to check if 'y' or 'Y' is entered.

Expand|Select|Wrap|Line Numbers
  1. if(tolower(inputAnswer[0]) == 'y')
  2.    // user wants "yes"
  3.  
Jul 7 '13 #5
Xillez
93 64KB
Thanks again for the help... I'll be back sometime in the future I persume...

Thanks again...
X
Jul 7 '13 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Bernard | last post by:
Hi, I have a problem with a CGI script (Perl) on a Win2000 server. The script is for sending E-cards and was written by Jason Maloney:...
1
by: max | last post by:
RDBMS Version:: 10.1.0.3.0 Operating System and Version:: MAC OS X 10.4.2 Product Version:: ORACLE Db10g Version 10.1.0.3.0 OEM Console Operating System and Version:: I cannot install emca...
0
by: Chris | last post by:
I've been a long time user of Crystal Reports (7-8.5) and I am now attempting to use it within VS2003. I added it to my project today and keep getting this error? I've searched this newsgroup and...
11
by: darrel | last post by:
I'm modyfying an image upload and resizing script that we've had laying around for a long while. I'm getting a NullReferenceException error (see full error at bottom) from this line: Dim g...
7
by: coolindienc | last post by:
I am trying to figure out what is wrong with this code. It says that global variable is not defined. Below is the error and code of the program. I have also highlighted the error place. Please...
0
by: GamingGeek | last post by:
Alright, I'm working on a project for class that I need to use both .gifs and .wavs. I've gotten the .wavs to work, but some of the gifs bring up a GDI+ error when I run the program. Here's the error...
0
by: =?Utf-8?B?dGVzaHRyYWRlQGdtYWlsLmNvbQ==?= | last post by:
Hi All, I am still new to Webservices in .NET Basically, This is what I am trying to accomplish. My Client has given me the soft copy of the WSDL file and XSD Files and has asked me to create...
2
by: speavey | last post by:
When I run this query, I get an ORDER BY error "Incorrect syntax near the keyword 'ORDER'. I've bolded it below. If I take the ORDER by out then it works correctly, but I need the ORDER BY...
2
by: aszush | last post by:
//Title: Programming Assignment 1 //Version: //Copyright: Copyright (c) 1999 //Author: Andrew //Company: //Description: Computes employee's weekly gross and net pay....
8
by: Jhei | last post by:
int get_value(void), get_rom(void); { /*Turbo C says I have a Declaration Syntax Error on this line.*/ int val, roman; printf("Enter a Roman Numerical number: ");...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.