Hey every1, i am trying to write a program which fills in an array of integers which r multiples of 7 between -63 and 1000; but it doesnt seem like its working for me...heres the code:-
int main()
{
float db7;
int i;
int a=7;
cout<<"Multiples of 7\t\t"<<endl;
for (i=-63;i<=1000;i++)
{ db7 = a * (i % a);
cout<<setprecision(2)<<"\n"<<db7;
Put it in code tags! You can't just throw code at people! It's practically illegible!
(I'm sorry but I've said that so many times.)
Now what isn't working and what output are you trying to get?
By the way this is a civilized forum, and we don't abbreviate are or one. If you don't have the time to type out a, then r, then e, or o, then n, then e, I definitely don't have the time to answer.
My apologies, I am just in a hurry when I type. My teacher asked me to create a program which fills in an array of multiples of 7 between -63 and 1000; then he asked me to use the function
int binsearch(int x, int v[], int n)
to find out in which element the value 721 is stored, print this information to the screen. And output some informative message, in case you have mistyped the value, for example as 712.
I am very new to the C++ world and I am using Microsoft Visual Studio 2008 to write the program and all I have reached to till now is the following ( I do not understand what you mean to put my codes in tags, I just copy and paste, I am sorry if that is causing any inconvenience for you):-
int main()
{
int db7;
int i;
int a=7;
int set;
cout<<"Multiples of 7\t\t"<<endl;
for (i=-63;i<=1000;i++)
{ db7 = i % a;
if (db7 == 0)
{
int set[] = {i};
int binsearch (int x, int y)
{ if ( x = set[y])
{
cout<<" The element in which the value 721 is stored is "<<x;
}
}
By code tags he mean a function on this forum to make code easier to read(i will show you an example). If you are new to c++ i really recommend you take a look at the tutorials on this site, or your own resource, and not try and attempt programs that are above your current skill level; it will only waste your time. Take a look at this program and try and follow it, it is based on your OP:
#include <iostream>
int main()
{
int multsOfSeven[1024];
int x = 0;
for(int i=-63;i<=1000;i++) {
if(!i) // can be writen as: if(i != 0) ... i just prefer my syntax
continue; // skip to next iteration
if(!(i%7)) // again, if((i % 7) != 0) ...
multsOfSeven[x++] = i; // add the value of i to the array "multsOfSeven" at element i then increment it.
/* you could write:
multsOfSeven[x] = i;
x++;
*/
}
for(int i=0;i<x;i++)
std::cout << multsOfSeven[i] << "\n"; // out the contents of the array
std::cin.get();
return 0;
}
Alright, thanks alot for the help on that; I am not trying to create programs above my level, it is just that I have an a C++ assignment to finish and I have been working on it ever since yesterday; there were two parts that I was stuck on but the first part, I managed to finish it with the help of someone on this forum. Now this is the second part, you have helped me through the first portion of it but I do not know how to execute the second portion which the teacher asked me to do:-
use the function
int binsearch(int x, int v[], int n)
to find out in which element the value 721 is stored, print this information to the screen. And output some informative message, in case you have mistyped the value, for example as 712.
Hmmm... I can understand the first and second parameters but I have no idea why you would need the third? Also, I don't unserstand the whole mistyping the value part; if you program is running a for loop and working the values out for you, where is there any room for user input let alone user mistakes?
guys when making posts, look at the all the little buttons on the right ----->
those buttons there are to format your posts, the <> button places code tags in you posts [ code] tags [/code ] and the same goes for quotes, the quote button is a picture of inverted commas, bold is a big B italic is a big I underline is a big underlined U, etc etc etc
while a lot of simple examples don't particularly need code tags, it's still good practice to use them.
@bolo89... The only part of my program that you have modified(in fact, removed) is a very important line. I put it there for a reason. The modulus of 0 is undefined in most systems so you need to check the value of 'i' before you perform the operation.