A little C++ problem.

Questions about programming languages and debugging
Post Reply
User avatar
Stavros
ΜΟΛΩΝ ΛΑΒΕ
ΜΟΛΩΝ ΛΑΒΕ
Posts: 1091
Joined: 02 Jan 2006, 17:00
15
Location: Mississippi, U.S.A.

A little C++ problem.

Post by Stavros »

I know it's a simple program, but I'm having trouble. Here's the code:

Code: Select all

#include <iostream>
#include <stdio.h>
using namespace std;

int main(int argc, char *argv[])
{
  int userNumber;
  userNnumber = 1-10
  cout << "Enter a number 1-10";
  cin >> userNumber;
  cout << "<< userNumber<<" \n\n";
  system("PAUSE");
  return 0;
}
I'm having trouble with the semicolon on after the escape sequence on line 11. The problem is that it won't turn black. It stays red and I keep getting this error: "12 ioproblems_code.cpp
unterminated string or character constant
". Thanks for any help.

User avatar
maboroshi
Dr. Mab
Dr. Mab
Posts: 1610
Joined: 28 Aug 2005, 16:00
15

Re: a little C++ problem

Post by maboroshi »

I don't know to much about C++
but I tested it and found a few things wrong I will try explain what I did
explanantions are in comments in the code

Code: Select all

#include <iostream>
#include <stdio.h>
/* here I included stlib.h for system(PAUSE) */
#include <stdlib.h>
using namespace std;

int main(int argc, char *argv[])
{
  int userNumber;
  userNumber = 1-10;
  cout << "Enter a number 1-10 ";
  cin >> userNumber;
  /* You don't need the first quotation marks here or <<*/
  cout << userNumber << " \n\n";
  system("PAUSE");
  return 0;
}
But good job in writing what you did so far I think your problem was the quotation marks on line 11 were just a little off

anyway good luck to you in your learning

User avatar
Stavros
ΜΟΛΩΝ ΛΑΒΕ
ΜΟΛΩΝ ΛΑΒΕ
Posts: 1091
Joined: 02 Jan 2006, 17:00
15
Location: Mississippi, U.S.A.

Post by Stavros »

Yay, it worked! I think I'd still be scratching my head as to what was wrong. Thanks, man.

User avatar
Nerdz
The Architect
The Architect
Posts: 1127
Joined: 15 Jun 2005, 16:00
15
Location: #db_error in: select usr.location from sucko_member where usr.id=63;
Contact:

Post by Nerdz »

Ok can I add few things?

1. LINE 7 : You don't need to affect your variable bcz your already doing so on line 9 with you cin. By the way, int is number and what caused you problem was 1-10

2. LINE 10 : sorry but this line simply don't fit... try this one

Code: Select all

 cout << userNumber << endl; 
The endl stuff is the same as " /n/n" and it's more beautiful :P
Give a man a fish, you feed him for one day.
Learn a man to fish, you feed him for life.

User avatar
maboroshi
Dr. Mab
Dr. Mab
Posts: 1610
Joined: 28 Aug 2005, 16:00
15

Cheers Nerdz

Post by maboroshi »

Hey good advice Nerdz

Your C++ is a lot better than mine

Cheers

Maboroshi

Post Reply