Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,151,558 members, 7,812,790 topics. Date: Monday, 29 April 2024 at 07:23 PM

C++ Compiling Error - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / C++ Compiling Error (785 Views)

Best App For Writing And Compiling Programs On Android Devices / Using AJAX For Server Side Compiling / Compiling From Source Codes (2) (3) (4)

(1) (Reply) (Go Down)

C++ Compiling Error by cruworld(m): 9:28am On Apr 04, 2011
#include <iostream>

using namespace std;
int main ()
{
int a,n;
int sum = 0;
int avg;
int count;

for(count=0;a>0;++count)
{
cin>>a;
}
n = count - 1;
cout<<count<<" "<<n;

cin.get();
return 0;
}

Please why is it that after compiling the program, it display the result and exit without pressing the enter key. Same thing to other programs that return values. but printing strings dosen't do like that.
Re: C++ Compiling Error by sweetpawn1: 12:18am On Apr 05, 2011
HALLO,
WHAT EXACTLY DO YOU WANT TO DO?
COUNT NUMBERS FROM 1 TO 10 OR CALCULATE THE AVERAGE? ITS KINDA DIFFICULT GIVING YOU THE REPLY COS AM A BIT CONFUSED ABOUT YOUR CODE!
Re: C++ Compiling Error by segsalerty(m): 7:58am On Apr 05, 2011
use


getch();


before your return 0; in ur main method, ok ?
Re: C++ Compiling Error by kodewrita(m): 8:20am On Apr 05, 2011
#include <iostream>

using namespace std;
int main ()
{
int a,n;
int sum = 0;
int avg;
int count;

for(count=0;a>0;++count)
{
cin>>a;
}
n = count - 1;
cout<<count<<" "<<n;

cin.get();
return 0;
}

my guess is that when you run this program:

The for loop will not work because a is 0 by default (its an integer and you have not initialised it with a value.) so it just falls through the fall loop. (a>0 is not true and hence the loop cant proceed.)

as earlier said, you can use cin.get(); or simply cin>>p;

Am tempted to write a program to do what you want but I guess this is a class assignment so I wont do that.

get a textbook and take it one line at a time.

its easy.
Re: C++ Compiling Error by sweetpawn1: 9:14am On Apr 05, 2011
AH, WORKS LIKE A CHARM!
THIS POST WAS LARGELY IGNORED UNTIL I CAME AND FEIGNED IGNORANCE ON ITS SOLUTION.
IMMEDIATELY FOLKS RUSHED IN TO SHOW OFF THEIR REMARKABLE TALENTS. ITS EASY TO GET NIGERIANS TO DO WHAT YOU WANT THEM TO DO FOR YOU, ONCE YOU KNOW THEIR PATTERN! grin
WELL, GOODLUCK TO THE OP. I GUESS NOW YOUR PROBLEM'S SOLVED!
Re: C++ Compiling Error by segsalerty(m): 12:32am On Apr 06, 2011
sweet-pawn:

AH, WORKS LIKE A CHARM!
THIS POST WAS LARGELY IGNORED UNTIL I CAME AND FEIGNED IGNORANCE ON ITS SOLUTION.
IMMEDIATELY FOLKS RUSHED IN TO SHOW OFF THEIR REMARKABLE TALENTS. ITS EASY TO GET NIGERIANS TO DO WHAT YOU WANT THEM TO DO FOR YOU, ONCE YOU KNOW THEIR PATTERN! grin
WELL, GOODLUCK TO THE OP. I GUESS NOW YOUR PROBLEM'S SOLVED!

shocked shocked whats that suppose to mean? i dnt grab ur concept undecided
Re: C++ Compiling Error by sweetpawn1: 7:30am On Apr 06, 2011
Ah, don't mind me! I was just thinking aloud!
Re: C++ Compiling Error by segsalerty(m): 11:56pm On Apr 06, 2011
sweet-pawn:

Ah, don't mind me! I was just thinking aloud!

i see ,

(1) (Reply)

Why Is This Not Working For Me / Mcts / How Do I Retrieve Fields From The A Java Derby Database

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 13
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.