[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
C++ Arrays and loops
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 34
Thread images: 3
File: SR2hUhQN_400x400.png (50 KB, 400x400) Image search: [Google]
SR2hUhQN_400x400.png
50 KB, 400x400
Hey /g/, I'm trying to create a program that will prompt the user to input a floating point value. It will save each value in an array. When the user inputs a 0, the program will close the loop and display every value whether it's positive or negative.
>>
Do you like anime?
>>
>>54502497

bool autism = true;
>>
>>54502497
Why have you sullied my eyes with this VisualShitdo ?. Pajeet, fuck off and do your homework. Poo in Loo is todays programming lesson.
>>
>>54502497
linked list
>>
>>54502497
Ok?
>>
This sounds like Intro to CS homework. Just read your textbook. If you don't put in the work now, you will fail later on.
>>
>>54502497
float dicks[500];
int i = 0;
for(;dicks[i] != 0; i++){
cout << ""gimme that shit: ";
cin >> dicks[i];
}
for(int j = 0; i>=j;j++)
cout<< dicks[i];

probably riddled with bugs and off by one errors but i think thats the gist.
>>
What part do you need help with. And does it have to be an array? And does it need to save the array after the program closes?
>>
Doesn't have to save the array after the program closes. Just display the values when the user inputs a 0.
>>
either ask the user how many entries they are going to list before getting the data so you can initialize the array with a size, or use a resizable data type such as vector/linked list/stack/queue
>>
>>54502497
so? go ahead and do it.
if you have legit questions, ask them, but don't come here wanting /g/ to straight up do your homework.
>>
if(userinput==0){
for(int i = 0; i < size; i++){
cout << array[i];
}
}
>>
This isn't any kind of homework /g/, just needed your help with my own work. Cheers guys
>>
>>54502578
Unemployed neets like yourself would say something like that.
>>
>>54502598
This is disgusting
>>
File: 1462377923584_1.jpg (101 KB, 755x423) Image search: [Google]
1462377923584_1.jpg
101 KB, 755x423
>>54502497
>>
>>54502752
>babbys first loop
>not homework
>>
>>54502497
>V2
>now with spoon feeding

#include <iostream>


using namespace std;
int main(){
float dicks[500];
int i = 0;
for (; dicks[i] != 0; i++){
cout << "gimme that shit : ";
cin >> dicks[i];
if ((int)(dicks[i]+.99999999) == 0)
break;
}
for (int j = 0; i >= j; j++)
cout << dicks[i];

}
>>
>>54502752
bro your straight up doing hw stfu. what kind of programmer cant make a loop.
>>
>>54502768
did i mention i'm an outsourced Indian software engineer?
>>
Wouldn't it be easier to push it onto a vector? That way the vector could dynamically grow depending on the elements. That, or a linked list
>>
>>54502801
youre wasting memory/potentially causing problems for user who needs to enter over 500 entries by defining the array as 500 instead of getting size from user.
>>
>>54502497
>>54502801
Did my program satisfy your needs????
>>
double Input;
vector<double> V;
cout << "Enter floating-point values, 0 to exit: ";
while (cin >> Input && Input != 0) V.push_back(Input);
for (auto& v : V) cout << v << endl;

You can do extra checks for illegal characters if you want.
>>
>>54502878
i am making a program based on the limited instructions i was given.
>>
wait

You want 3.1415926535897932384626433 8327950 to be stored as array[]={3,1,4,1,5,9...,0} ?

is that what you meant?
>>
>>54502938
oo that sounds more fun
>>
Ill write this for you, but you have to be more clear. Is it like >>54502938 said? Or i enter 3.4, then 0.454, then 1.144 , then 2.0, then 0.
The program displays each of those numbers individually, one after the other?
>>
>>54502497
this is the most consice:
#include <cstdlib>

int main(int argc, char **argv){
for (;;)
std::system(argv[0]); // <- array input and display handled by cstdlib
return 0;
}
>>
>>54502967
I already wrote it see
>>54502967
>>
>>54502988
Recursion! no....
correction: >>54502801
>>
File: 1453150878738.jpg (16 KB, 714x547) Image search: [Google]
1453150878738.jpg
16 KB, 714x547
>its getting towards the end of the semester
>this is OP's final assignment for his shitty cc programming class
what kind of programming do they teach at the cc? and why is OP a retard
>>
>>54502967
I read again and am sure OP just mean the program repeatedly asks for input until the user enters a 0. Really, just basic homework.
Thread replies: 34
Thread images: 3

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.