11 Replies - 900 Views - Last Post: 11 April 2011 - 12:29 PM Rate Topic: -----

#1 computer woman   User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 11
  • Joined: 10-April 11

i have error in my code

Posted 10 April 2011 - 10:27 AM

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

struct benchmark {
string name;
int IC;
float CPI;
float CCT;
float EX;
float MIPS;

};




int main(int argc,char *argv[])
{

float  EX;
float MIPS;
int size;
int i;
float a,c,s,e;
benchmark*b;
size= atoi(argv[i]);
b =new benchmark[size];

ifstream myfile;

 myfile.open ("c://baraa.txt",ios::in);

{ 

cout<<"number of benchmark is:";

for (int i=0;i<size;i++)

 cout<<"enter benchmark "<<i<<"name"<<endl;
cin>>b[i].name;
cout<<"cct["<<i<<"]= ";
cin>>b[i].CCT;
cout<<"cpi["<<i<<"]= ";
cin>>b[i].CPI;
cout<<"ic["<<i<<"]= ";
cin>>b[i].IC;


b[i].EX = b[i].IC* b[i].CPI* b[i].CCT;

cout<<" the ex is "<<EX<<endl;

a=(1/b[i].CCT);
c=(b[i].EX * 1000000);
MIPS=a/c;

cout<<"MIPS for benchmark is:"<<MIPS<<endl<<endl;

cout<<"**************************************"<<endl;
	
{int max1=b[0].MIPS;
if(b[i].MIPS > max1){
	max1=b[i].MIPS;
}
	for(int j;j<max1;j++)
	for(int s;s<j;s++)
	
cout<<s;
};

{int max2=b[0].EX;
if(b[0].EX > max2){
	max2=b[i].EX;
}
	
{for(int k;k<max2;k++)
for(int e;e<k;e++)
cout<<e;
};
		
	ofstream myfile("c:\\baraa.text",ios::out);
	cout<<"MIPS IS:"<<s;
	cout<<"EXCUTION TIME IS:"<<e;

 myfile.close();
 


cout<<endl;

return 0;
}





error in my code is
unexpected end of file .....what is the solution
i have 2 day just ..please hurry up

This post has been edited by Martyr2: 10 April 2011 - 10:33 AM
Reason for edit:: Please use code tags in the future, thanks!


Is This A Good Question/Topic? 0
  • +

Replies To: i have error in my code

#2 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5224
  • View blog
  • Posts: 14,003
  • Joined: 18-April 07

Re: i have error in my code

Posted 10 April 2011 - 10:38 AM

*
POPULAR

Check your opening and closing braces. Your code is seriously whacked in the matching of opening and closing braces. Remember if you open a curly brace, you must close it at some point. The number of opening need to match the number of closing.

Oh and a tip for you in the future, NEVER come on a board asking for help and then say "hurry up". It just puts us in a bad mood and not want to help. We always try to do what we can and get to answers as fast as we can but we are volunteers and not a paid service. This goes for other boards too. Just so you know.

:)
Was This Post Helpful? 6
  • +
  • -

#3 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6246
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: i have error in my code

Posted 10 April 2011 - 10:41 AM

*
POPULAR

Wow, did you just throw braces ({) and } around there randomly or what? Here's what your code looks like with proper indentation:
#include <iostream>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include<fstream>
using namespace std;

struct benchmark {
    string name;
    int IC;
    float CPI;
    float CCT;
    float EX;
    float MIPS;

};




int main(int argc,char *argv[])
{

    float  EX;
    float MIPS;
    int size;
    int i;
    float a,c,s,e;
    benchmark*b;
    size= atoi(argv[i]);
    b =new benchmark[size];
    
    ifstream myfile;
    
    myfile.open ("c://baraa.txt",ios::in);
    
    { 
        
        cout<<"number of benchmark is:";
        
        for (int i=0;i<size;i++)
            
            cout<<"enter benchmark "<<i<<"name"<<endl;
        cin>>b[i].name;
        cout<<"cct["<<i<<"]= ";
        cin>>b[i].CCT;
        cout<<"cpi["<<i<<"]= ";
        cin>>b[i].CPI;
        cout<<"ic["<<i<<"]= ";
        cin>>b[i].IC;
        
        
        b[i].EX = b[i].IC* b[i].CPI* b[i].CCT;
        
        cout<<" the ex is "<<EX<<endl;
        
        a=(1/b[i].CCT);
        c=(b[i].EX * 1000000);
        MIPS=a/c;
        
        cout<<"MIPS for benchmark is:"<<MIPS<<endl<<endl;
        
        cout<<"**************************************"<<endl;
        
        {
            int max1=b[0].MIPS;
            if(b[i].MIPS > max1)
            {
                max1=b[i].MIPS;
            }
            for(int j;j<max1;j++)
                for(int s;s<j;s++)
                    
                    cout<<s;
        };

        {
            int max2=b[0].EX;
            if(b[0].EX > max2)
            {
                max2=b[i].EX;
            }
	
            {
                for(int k;k<max2;k++)
                    for(int e;e<k;e++)
                        cout<<e;
            };
            
            ofstream myfile("c:\\baraa.text",ios::out);
            cout<<"MIPS IS:"<<s;
            cout<<"EXCUTION TIME IS:"<<e;
            
            myfile.close();
            
            
            
            cout<<endl;
            
            return 0;
        }
        



Can you tell what's wrong now?

Here's a tip for you if you post another question: DON'T tell us to "hurry up"! We're here as volunteers, NOT your SLAVES!

This post has been edited by JackOfAllTrades: 10 April 2011 - 10:42 AM

Was This Post Helpful? 5
  • +
  • -

#4 computer woman   User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 11
  • Joined: 10-April 11

Re: i have error in my code

Posted 10 April 2011 - 11:34 AM

JackOfAllTrades and Martyr2 thanx for help but it not work
can you help me with another solution

I'm sorry I do not mean to insult anyone but I am very compelled to get an answer
thanx for all and I'm sorry again
Was This Post Helpful? -1
  • +
  • -

#5 computer woman   User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 11
  • Joined: 10-April 11

Re: i have error in my code

Posted 11 April 2011 - 10:59 AM

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

struct benchmark {
string name;
float IC;
float CPI;
float CCT;
float EX;
float MIPS;

};
int main(int argc,char *argv[])
{

float  EX;
float MIPS;
int size;
int i;
float a,c;
int s,e;
benchmark*b;
if (argc<2){
cout<< "command line error"<<endl;
}


size= atoi(argv[i]);
b =new benchmark[size];

cout<<"number of benchmark is:"<<size;



ifstream myfile;

 myfile.open ("c://archi.txt",ios::out);

for (i=0;i<size;i++)

 myfile>>b[i].name;
myfile>>b[i].IC;
myfile>>b[i].CPI;
myfile>>b[i].CCT;


b[i].EX = b[i].IC* b[i].CPI* b[i].CCT;

cout<<" the ex is "<<b[i].EX<<endl;

a=(1/b[i].CCT);
c=(b[i].EX * 1000000);
b[i].MIPS=a/c;

cout<<"MIPS for benchmark is:"<<b[i].MIPS<<endl<<endl;

cout<<"**************************************"<<endl;




int max1=b[0].MIPS;
if(b[i].MIPS > max1){
	max1=b[i].MIPS;
}
for(int j;j<max1;j++){
	for(int s;s<j;s++)
	
cout<<s;

};

int max2=b[0].EX;
if(b[0].EX > max2){
	max2=b[i].EX;
}
	
{for(int k;k<max2;k++)
for(int e;e<k;e++){
cout<<e;

};


ifstream myfile("c:\\baraa.text",ios::in|ios::app);
myfile>>"MIPS is">>"   ">>s;
myfile>>"excetion time is">>"    ">>e;

myfile.close();
return 0;
}


my error is:

unexpected end of file found

This post has been edited by macosxnerd101: 11 April 2011 - 11:44 AM
Reason for edit:: CODE TAGS!!! USE THEM!!!

Was This Post Helpful? 0
  • +
  • -

#6 LaughingBelly   User is offline

  • D.I.C Head

Reputation: 49
  • View blog
  • Posts: 109
  • Joined: 11-April 11

Re: i have error in my code

Posted 11 April 2011 - 11:25 AM

Please use code tags when you post your code. It is the least you could do to help us help you.

You also need to start indenting your code. It makes it super obvious as to why you are getting that error. See that when I indent the code, there is no closing } for main. I think your code has a few problems - fixing the ones I commented with ######### tagged would be a start.

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

struct benchmark {
    string name;
    float IC;
    float CPI;
    float CCT;
    float EX;
    float MIPS;

};
int main(int argc,char *argv[])
{

    float  EX;
    float MIPS;
    int size;
    int i;
    float a,c;
    int s,e;
    benchmark*b;
    if (argc<2){
        cout<< "command line error"<<endl;
    }


    size= atoi(argv[i]);
    b =new benchmark[size];

    cout<<"number of benchmark is:"<<size;



    ifstream myfile;

    myfile.open ("c://archi.txt",ios::out);

    for (i=0;i<size;i++)
    // ######### missing an opening {
        myfile>>b[i].name;

    myfile>>b[i].IC;
    myfile>>b[i].CPI;
    myfile>>b[i].CCT;


    b[i].EX = b[i].IC* b[i].CPI* b[i].CCT;

    cout<<" the ex is "<<b[i].EX<<endl;

    a=(1/b[i].CCT);
    c=(b[i].EX * 1000000);
    b[i].MIPS=a/c;

    cout<<"MIPS for benchmark is:"<<b[i].MIPS<<endl<<endl;

    cout<<"**************************************"<<endl;




    int max1=b[0].MIPS;
    if(b[i].MIPS > max1){
        max1=b[i].MIPS;
    }
    for(int j;j<max1;j++){
        for(int s;s<j;s++)

            cout<<s;

    };

    int max2=b[0].EX;
    if(b[0].EX > max2){
        max2=b[i].EX;
    }
    // ######### why the opening {?
    {for(int k;k<max2;k++)
        for(int e;e<k;e++){
            cout<<e;

        };


    ifstream myfile("c:\\baraa.text",ios::in|ios::app);
    myfile>>"MIPS is">>"   ">>s;
    myfile>>"excetion time is">>"    ">>e;

    myfile.close();
    return 0;
    }


Was This Post Helpful? 0
  • +
  • -

#7 vividexstance   User is offline

  • Tiocfaidh ár lá
  • member icon

Reputation: 792
  • View blog
  • Posts: 2,873
  • Joined: 31-December 10

Re: i have error in my code

Posted 11 April 2011 - 11:29 AM

You're also using C++ it seems, so you should include the standard versions. For example, instead of this:
#include <iostream>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <fstream>



It should be:
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <fstream>


Was This Post Helpful? 0
  • +
  • -

#8 computer woman   User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 11
  • Joined: 10-April 11

Re: i have error in my code

Posted 11 April 2011 - 11:32 AM

but when i click on the error the cursor point to line 97
can you help me

Was This Post Helpful? -2
  • +
  • -

#9 r.stiltskin   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2032
  • View blog
  • Posts: 5,435
  • Joined: 27-December 05

Re: i have error in my code

Posted 11 April 2011 - 11:36 AM

Can't you even bother to read when someone gives you the answer?

View PostLaughingBelly, on 11 April 2011 - 01:25 PM, said:

You also need to start indenting your code. It makes it super obvious as to why you are getting that error. See that when I indent the code, there is no closing } for main.

Was This Post Helpful? 0
  • +
  • -

#10 computer woman   User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 11
  • Joined: 10-April 11

Re: i have error in my code

Posted 11 April 2011 - 11:44 AM

i tried that but it not work
Was This Post Helpful? -1
  • +
  • -

#11 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6246
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: i have error in my code

Posted 11 April 2011 - 11:46 AM

Merged duplicated topics. Do NOT create a new topic when you already have one on the same subject!
Was This Post Helpful? 0
  • +
  • -

#12 jimblumberg   User is offline

  • member icon

Reputation: 5487
  • View blog
  • Posts: 17,062
  • Joined: 25-December 09

Re: i have error in my code

Posted 11 April 2011 - 12:29 PM

Show the code where you tried to fix the braces. Also post the entire complete error messages.

Jim
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1