Thread: How can i convert c++ to c (help!!!)

  1. #1
    Registered User
    Join Date
    Dec 2019

    How can i convert c++ to c (help!!!)

    hello everyone, how can i convert this code from C++ to C language. This is quite important to me. Please help me. thanks...

    #include <iostream>
    #include <vector>
    static const int UPPER_BOUND = 100;
    int main() {
    	std::vector<int> landings;
    	// Push in doubles.
    	for (int i = 1; i <= 20; ++i) {
    		landings.push_back(2 * i);
    	landings.push_back(2 * 25);
    	// Push in singles.
    	for (int i = 1; i <= 20; ++i) {
    	// Push in trebles.
    	for (int i = 1; i <= 20; ++i) {
    		landings.push_back(3 * i);
    	int nCheckOuts = 0;
    	for (int i = 0; i < 21; ++i) {
    		int sum = landings[i];
    		if (sum < UPPER_BOUND) {
    		for (int j = 0; j < 62; ++j) {
    			sum += landings[j];
    			if (sum < UPPER_BOUND) {
    			for (int k = j; k < 62; ++k) {
    				sum += landings[k];
    				if (sum < UPPER_BOUND) {
    				sum -= landings[k];
    			sum -= landings[j];
    	std::cout << nCheckOuts << std::endl;
    	return 0;

  2. #2

  3. #3
    Registered User
    Join Date
    Aug 2019
    inside a singularity
    Where's your attempt at converting this C++ code to C? That code is almost C...

    A vector is like an array. Make an array of size 62 and convert push_back accordingly
    cout to printf
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook, The Wizardry Compiled

  4. #4
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    As Zeus_ said it's basically C anyway.

    My reason for not answering you is that I don't think that plagiarism is good. I doubt your teachers think it's a good thing either. If I can find where you stole your source code from on my first attempt I'm pretty sure your teachers can as well. But, maybe you don't care.

    Anyway, moving on, it took me 30 seconds (literally) to convert that to C using Zeus_'s suggestions. I'm not going to paste the code here because it's not your code. I only bothered even looking at it more closely because the solution seemed different to my own solution of the same Project Euler problem.

    Is your course related to programming or mathematics?
    Last edited by Hodor; 12-29-2019 at 07:12 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 17
    Last Post: 07-26-2012, 09:32 PM
  2. c to c++ convert
    By sravani24 in forum C++ Programming
    Replies: 11
    Last Post: 12-06-2011, 12:04 AM
  3. cannot convert `int (*)[2]' to `int*
    By luoyangke in forum C Programming
    Replies: 9
    Last Post: 11-12-2009, 11:27 PM
  4. convert maybe maybe not..
    By pico in forum C Programming
    Replies: 7
    Last Post: 03-15-2005, 10:13 AM
  5. cannot convert
    By opafire in forum C++ Programming
    Replies: 3
    Last Post: 12-10-2003, 08:41 AM

Tags for this Thread