Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

got these errors, small ones. maybe someone can help.


  • Please log in to reply
5 replies to this topic

#1 TOMIS13LACK

TOMIS13LACK

  • Members
  • 213 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:07:14 PM

Posted 20 September 2015 - 04:25 PM

here is my code, wrote it as practice:

#include <iostream>
#include <string>
#include <fstream>

using namespace std;
 
int main()
{
  string age;
  int answer1;
  int answer2;
  int mew;
  int score;
  score = 0;
  cout << "What is your name? ";
  getline (std::cin, age);
  cout << "Hi " << age << ",wanna play a game? 1/2";
  getline (std::istream, answer1);
  if ( answer1 == 1 ) {
      cout << "Q1, What is 1+1?";
      if ( answer2 == 2 ) { score = score + 1;
        cout << "Congrats, you win! Your score is: " << score << ". Would you like to save it? (1/2)";
        getline (std::istream, mew);
        if ( mew == 1 ) {
            ofstream myfile;
            myfile.open ("Score.txt");
            myfile << "Name:" << age;
            myfile << "Score: " << score;
            myfile.close();
        }
          }
      else { score = score -1;
      cout << "You Lose, your score is: " << score << "!\n";
      }
  }
  else {
      return 0;
  }
}

and the error is:

18:24: error: expected primary-expression before ',' token
23:30: error: expected primary-expression before ',' token

I have read them and i think i understand but do not know what is to be defined as a primary-expression


ooh, i have a signature


BC AdBot (Login to Remove)

 


#2 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:04:14 PM

Posted 21 September 2015 - 12:18 PM

getline (std::istream, answer1);
I don't know what this is intended to do -- std::istream is a class, not an instance. It'd be like typing

getline (int, answer1);

Perhaps you meant std::cin, the instance of std::istream that corresponds to console input?

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#3 TOMIS13LACK

TOMIS13LACK
  • Topic Starter

  • Members
  • 213 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:07:14 PM

Posted 21 September 2015 - 04:24 PM

When i did cin, it game me an error and told me to use that instead. Now it is telling me i need something after istream and before the comma. Perhaps because it is an int and not a string.


ooh, i have a signature


#4 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:04:14 PM

Posted 21 September 2015 - 04:26 PM

When i did cin, it game me an error and told me to use that instead.

Post this error message.
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#5 TOMIS13LACK

TOMIS13LACK
  • Topic Starter

  • Members
  • 213 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:07:14 PM

Posted 21 September 2015 - 06:55 PM

it is in the original post, i got 2 errors.


ooh, i have a signature


#6 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:04:14 PM

Posted 21 September 2015 - 07:11 PM

The errors in your original post are caused by what I pointed out above. getline (std::istream, answer1);. getline is a function call, you need to pass a value to a function call, not a type. That is, this is not legal:
void example_function(int a)
{
    // does something with a
}

int main()
{
    example_function(int);
}
This is:
void example_function(int a)
{
    // does something with a
}

int main()
{
    int a_variable_that_happens_to_be_an_int = 42;
    example_function(a_variable_that_happens_to_be_an_int);
}

Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users