Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,151,601 members, 7,812,966 topics. Date: Tuesday, 30 April 2024 at 12:08 AM

C/c++ Helper. - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / C/c++ Helper. (2386 Views)

Programming FUN With Code Snippets!! -C++,C#, Java,php,python Or Any Language!! / Simple Code Challenge: C#, Java, C, C++ / Is C# Better Than C/C++? (2) (3) (4)

(1) (Reply) (Go Down)

C/c++ Helper. by profCC: 4:22am On Jun 29, 2011
#include<stdio.h>
main()
{
printf("AM A PROFESSIONAL C/C++ PROGRAMMER.\nI do realize that many people find it difficult to code in c/c++ language.\nAm HERE to fix that.\nTELL me the area you have problem.PROGRAMING IS FUN."wink;
}
Re: C/c++ Helper. by Fayimora(m): 6:53am On Jun 29, 2011
Welcome grin
Re: C/c++ Helper. by csharpjava(m): 1:12pm On Jun 29, 2011
Edited:
Thanks for starting this thread. Can you show an example of the code you would use to avoid a pointer from corrupting the memory space of the operating system?
Re: C/c++ Helper. by barlery: 10:35am On Jul 08, 2011
pls can i get a link to download C++ compiler.
thanks
Re: C/c++ Helper. by csharpjava(m): 12:59pm On Jul 08, 2011
barlery:

pls can i get a link to download C++ compiler.
thanks

http://sourceforge.net/projects/dev-cpp/files/Binaries/Dev-C%2B%2B%204.9.9.2/devcpp-4.9.9.2_setup.exe/download
Re: C/c++ Helper. by mikeblitz: 4:11am On Dec 15, 2011
guys i need help ASAP since i need to submit this miniproject and i need 1 more minor questions need asnwered.

the C++ coding is given below, i need to change it to function type but giving out the same output.


#include <iostream>
#define SIZE 7
using namespace std;

int main()
{

int A[ SIZE ] = { 2, 4, 8, 16, 32, 64, 128};
int i, j;
int total = 0;


cout <<"Value of array: ";
for ( j = 0; j <SIZE; j++)
cout<< A[j] <<" ";
cout<<endl;

for ( i = 0; i < SIZE; i++ )
{
total += A[i];
}

cout << "Total of 2 power n from 2 to 128 are: "<<total;
return 0;

}


thanks in advance if anyonemanaged to answer it within 30 minutes from now.
Re: C/c++ Helper. by SonoraRose: 4:47am On Dec 15, 2011
Hi Mikeblitz,

If I understand the question correctly, you are asked to use a function in the main.
So all you have to do is move the current code you see in main into a function that you'll define.

For example:


#include <iostream>
#define SIZE 7
using namespace std;

//define and declare a new function
void power_of_two () {

int A[ SIZE ] = { 2, 4, 8, 16, 32, 64, 128};
int i, j;
int total = 0;


cout <<"Value of array: ";
for ( j = 0; j <SIZE; j++)
cout<< A[j] <<" ";
cout<<endl;

for ( i = 0; i < SIZE; i++ )
{
total += A[i];
}

cout << "Total of 2 power n from 2 to 128 are: "<<total;

}

int main()
{

power_of_two();

return 0;

}


My answer is pretty simplistic. Hopefully that's what your teacher is asking for.

Best of Luck!
Re: C/c++ Helper. by auwalup(m): 8:27pm On Dec 15, 2011
Any one with any idea {am using bloodshed devc\cpp} am trying to attach the grafix.h header file i downloaded but cant get it right
Re: C/c++ Helper. by lordZOUGA(m): 8:42pm On Dec 16, 2011
SonoraRose:

Hi Mikeblitz,

If I understand the question correctly, you are asked to use a function in the main.
So all you have to do is move the current code you see in main into a function that you'll define.

For example:


#include <iostream>
#define SIZE 7
using namespace std;

//define and declare a new function
void power_of_two () {

int A[ SIZE ] = { 2, 4, 8, 16, 32, 64, 128};
int i, j;
int total = 0;


cout <<"Value of array: ";
for ( j = 0; j <SIZE; j++)
cout<< A[j] <<" ";
cout<<endl;

for ( i = 0; i < SIZE; i++ )
{
total += A[i];
}

cout << "Total of 2 power n from 2 to 128 are: "<<total;

}

int main()
{

power_of_two();

return 0;

}


My answer is pretty simplistic. Hopefully that's what your teacher is asking for.

Best of Luck!

very very much simplistic, dat it looks much more lyk his original problem, I think his tutor wud be impressed if he declares everything in the main then define a function that prints the contents of the array and then define another function that finds the total of the array and prints it

(1) (Reply)

Developer Integrates Interswitch's Webpay With Wordpress Plugin / Open Source Affiliate Management System / Tutorial: How To Build Payment Gateway

(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. 22
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.