Problems creating new line

This is a discussion on Problems creating new line within the C++ Programming forums, part of the General Programming Boards category; I'm a new to C++ in VB . I was wondering if anyone knows why i keep getting errors in ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    10

    Exclamation Problems creating new line

    I'm a new to C++ in VB. I was wondering if anyone knows why i keep getting errors in VB when creating a new line using \n.

    I keep getting the following error
    1>------ Build started: Project: CjohnsonAS1, Configuration: Debug Win32 ------
    1>Compiling...
    1>cjohnsonAS1.cpp
    1>c:\users\christian\documents\visual studio 2005\projects\cjohnsonas1\cjohnsonas1\cjohnsonas1. cpp(23) : error C2017: illegal escape sequence
    1>c:\users\christian\documents\visual studio 2005\projects\cjohnsonas1\cjohnsonas1\cjohnsonas1. cpp(23) : error C2146: syntax error : missing ';' before identifier 'n'
    1>c:\users\christian\documents\visual studio 2005\projects\cjohnsonas1\cjohnsonas1\cjohnsonas1. cpp(23) : error C2065: 'n' : undeclared identifier
    1>c:\users\christian\documents\visual studio 2005\projects\cjohnsonas1\cjohnsonas1\cjohnsonas1. cpp(26) : error C2017: illegal escape sequence
    1>c:\users\christian\documents\visual studio 2005\projects\cjohnsonas1\cjohnsonas1\cjohnsonas1. cpp(26) : error C2146: syntax error : missing ';' before identifier 'n'
    1>c:\users\christian\documents\visual studio 2005\projects\cjohnsonas1\cjohnsonas1\cjohnsonas1. cpp(29) : error C2017: illegal escape sequence
    1>c:\users\christian\documents\visual studio 2005\projects\cjohnsonas1\cjohnsonas1\cjohnsonas1. cpp(29) : error C2146: syntax error : missing ';' before identifier 'n'
    1>Build log was saved at "file://c:\Users\christian\Documents\Visual Studio 2005\Projects\CjohnsonAS1\CjohnsonAS1\Debug\BuildL og.htm"
    1>CjohnsonAS1 - 7 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    The actual script i created is as followed
    insert
    Code:
    #include <iostream>
    #include <iomanip>
    using namespace std;
    int main()
    
    {
    double salary_yr = 0,
        yearly_rate = 0,
        intrest_calc = 0,
        intrest_calc2 = 0,
        intrest_calc3 = 0,
        total_yr1 = 0,
        total_yr2 = 0,
        total_yr3 = 0;
    const double converson = 0.06;
    
    cout << "enter your current anual pay: ";
    cin >> salary_yr;
    cout << "enter percentage of anual salary increse: ";
    cin >> yearly_rate;
    intrest_calc = salary_yr * converson;
    total_yr1 = intrest_calc + salary_yr;
    cout << " annual salary intrest for year one "<<total_yr1 \n;
    intrest_calc2 = total_yr1 * converson
    ;total_yr2 = total_yr1 + intrest_calc2;
    cout << " annual salay increase of second year is "<<total_yr2 \n;
    intrest_calc3 = total_yr2 * converson;
    total_yr3 = total_yr2 + intrest_calc3;
    cout << " annual salary increase of second year is "<<total_yr3 \n;
    return 0;
    }
    could anyone explain to my why i can not compile this program and why it keeps saying /n is whats causing the error . or is that even what the Error message is saying. Any tips btw would be greatly appreciated. as i mentioned before I am new to programming...
    thanks
    cj

  2. #2
    dra
    dra is offline
    Weak. dra's Avatar
    Join Date
    Apr 2005
    Posts
    166
    \n is a character so you need to treat it as such. you could also use std::endl

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    Replace each instance of \n in your code with

    << '\n'

    (with a semicolon at the end, which you already have).

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Try:
    Code:
    cout << " annual salary interest for year one " << total_yr1 << endl;
    If you want something to go out, you have to move it out with <<.

    PS: You might want to look into using actual indentation. (It's not a big deal, yet, but it will be within the next few assignments.) And, maybe not misspelling nearly every word of six or more letters will help later as well.

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,604
    http://cpwiki.sf.net/User:Elysia/Indentation
    For indentation needs, when you need them.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer and Polymorphism help.
    By Skyy in forum C++ Programming
    Replies: 29
    Last Post: 12-18-2008, 08:17 PM
  2. Printing Length of Input and the Limited Input
    By dnguyen1022 in forum C Programming
    Replies: 33
    Last Post: 11-29-2008, 03:13 PM
  3. Problems with returning a char* to fprint.
    By qubit67 in forum C Programming
    Replies: 5
    Last Post: 08-08-2007, 11:28 PM
  4. if is faster than switch?
    By skorman00 in forum C++ Programming
    Replies: 32
    Last Post: 03-06-2004, 12:15 PM
  5. Greenhand want help!
    By leereg in forum C Programming
    Replies: 6
    Last Post: 01-29-2002, 05:04 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21