Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 135,951 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,679 people online right now. Registration is fast and FREE... Join Now!




Number Reversing Prog: error C2059: syntax error : '}'

 
Reply to this topicStart new topic

Number Reversing Prog: error C2059: syntax error : '}'

thebath
11 May, 2008 - 05:17 AM
Post #1

New D.I.C Head
*

Joined: 11 May, 2008
Posts: 5

Gwin is the graphics window we have to use, pretty simple most of the commands are self explanitory.
Anyway i got the error in the topic and cant work out why its throwing me and error about the closing brace of the program. Help appreciated cheers

CODE


#include "stdafx.h"
#include "gwin.h"
#include <string>
#include <iostream>
#include <time.h>
#include <sstream>

using namespace std;

int main()
{
    
    
    bool flag=true;
    int ans=1;
    do
    {
    int Number; //to be entered by user
    int ReversedNumber=0; //initialise to zero since should start with nothing
    int LastDigit; // taken off each time
    // Clear the Gwin window
    Gwin.clear();

    //Prompt user for number to be reversed
    Gwin.writeText(0,0, "Enter positive integer to be reversed: ");
    Number = Gwin.getInt();
    while (Number>0)
    {
        LastDigit = Number%10; //will be between 0 and 9    
        ReversedNumber = ReversedNumber*10 + LastDigit;
        Number = Number/10; //integer divide, so will lose last digit eg goes from 1234 to 123
    

    // Output the reversed number
    Gwin.writeText(0, 20, "The reversed number is : ");
    Gwin.writeInt(200, 20, ReversedNumber);
    Gwin.writeText(0, 50, "Press 0 to end any number to reverse another number: ");
    flag=Gwin.getInt();
    
    if(flag==false)
    {break;
    }

    }

    // Finally, wait for a key to be pressed
    Keyboard.getch();

    return 0;
    }
}

User is offlineProfile CardPM
+Quote Post

silv3rback
RE: Number Reversing Prog: Error C2059: Syntax Error : '}'
11 May, 2008 - 05:46 AM
Post #2

New D.I.C Head
*

Joined: 10 May, 2008
Posts: 5

The program expects closing braces followed by the while condition for your do-while loop. At the moment, it considers the while loop to be a nested inside the do-while loop. The syntax for the do-while loop is:
CODE
do {
//body of the loop
}while(condition);


I haven't looked at your program thoroughly, but I would guess if you put the statements you are currently using inside the nested while-loop, to within the do-while's braces, you will solve the error.

Hth
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 09:06AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month