- Strength to Increase Rep
- +5
- Strength to Decrease Rep
- -1
- Upvotes Received
- 2
- Posts with Upvotes
- 1
- Upvoting Members
- 2
- Downvotes Received
- 0
- Posts with Downvotes
- 0
- Downvoting Members
- 0
Re: If max is the number of primes ,you originally want then why are you looping to maxprimes (or is it[I] MAXPRIMES[/I]) ( @siddhant3s : [QUOTE] if you can make it run, get us back. [/QUOTE] ) [CODE] //while (count < maxprimes) //shouldn't it be (count < max) [/CODE] But even … | |
Re: Even this line needs some correection: [CODE=c] scanf("&d", &items); [/CODE] In your second program, why do you think [CODE=c] float ratio, score=0, items; [/CODE] the number of items should be in floats.The reason why i ask is this: [CODE=c] for(count=0; count!=items; count++) [/CODE] Mixing integers and floats may lead to … | |
Re: [CODE=c] char Repeat ; . . cin >> Repeat ; [/CODE] Possibly you take BMI as input which leaves a '\n' in buffer which is accepted by [ICODE]Repeat[/ICODE] and you don't get a yes / no chance. Either clear the buffer using standard C++ way or use strings [ICODE]string Repeat;[/ICODE] … | |
Re: Search for aheader file which contains these functions under Turbo C [CODE=C] getch(); clrscr (); gotoxy (35,12); [/CODE] | |
Re: hmm, let's C:twisted: [CODE=c] void userInput (int matrix[R_SIZE][C_SIZE], int row, int col) //gathering user input { /*You are using a for loop in main().This function just accepts input for a paticular row and column*/ /* This is the trouble >> scanf("%d", &matrix[R_SIZE][C_SIZE]); Here is the major problem.This should have resulted … | |
Re: [QUOTE=gretty;955772]Hello I have a program that prints a menu & the user is prompted to input a choice(1,2 or 3) if they input anything else, the output should be "Invalid Choice". [B] My Problem[/B] is that if a user inputs anything other than 1,2 or 3, then the program crashes, … | |
Re: [QUOTE=gretty] I am supposed to use a binary search ... [/QUOTE] Binary Search would come into picture only iff you have a sorted input like dell, bell etc and corresponding sorted array to search for. Your examples don't have a sorted string in most of the cases. But if we … | |
Re: [QUOTE] void selection_sort(double input_array[], int input_size); void display_array(double input_array[], int input_size); [/QUOTE] True. But the program still wouldn't work This line [CODE] int small, temp; [/CODE] small (its the index)is Ok but temp stores the value of the element in the double[] input_array, so you will always have a truncated … | |
Re: I doubt whether this will help..:S , your read_in file remains intact, your read_out now is: [CODE=c++] #include <iostream> #include <string> using namespace std; int main() { string word; // even while((cin >> word)) works while(getline(cin, word)) for (int i = 0; i < word.length(); i++) cout << word[i] << … | |
Re: I didn't want to poke but [I]firstPerson[/I]'s method doesn't take into account the frequency of characters, so for inputs like s1 = roorsseett s2 = sosretetet returns true. letter s1 s2 r 2 1 o 2 1 . . or inputs like s1 = rorre s2 = oroee returns true. … | |
Re: You haven't said anything about the desired output of your program, the total you were expecting, what testsdid you do , if you ae using compound interest, then the formula looks wrong to me. Whether the interest rates are given directly or you are supposed to divide by 100 and … | |
Re: [CODE] double interest = .00575; [/CODE] I think the monthly interest is given. [CODE] double monthlyInterest = interest * 12; [/CODE] is actually the yearlyInterest which comes to ~ 7 %. Well, if you are calculating the total with the 'monthly' interest, the formula should have been [CODE] total = … | |
Re: Well,It also gives me an error. [CODE] syntax error before else [/CODE] every where when you have else statements coming ahead of else if statements. May be we can alter the structure of the program , if suppose you have a candidate getting less than 35, you still get into … | |
Re: [quote] I dont know how work with the overtime... here's my code.. [CODE=c]#include <stdio.h> int main() { int day,hRate,wHours,; int total = 0; int i = 1; float cTax,gross,salary,nSalary,aTotal; float tax = .12; printf("Enter Hourly Rate: "); scanf("%d",&hRate); printf("Enter number of days you've worked: "); scanf("%d",&day); if (i <= day) … | |
Re: [quote] int index=0; while(arr[index] != 15) //15 as an example the value we r looking for { index++; } [/quote] What if '15' does not exist in the array, what happens then ? How far will index go ? or, if there are multiple copies of '15'? | |
Re: Another approach could be 1.Make another userGuess string. 2. First , fill all the characters in userGuess string with underscores( _ ). 3.Make changes in the userGuess string. [CODE=cplusplus] guess(); //call member function of letter chosen ltrpos = gameWord.find(gameGuess); cout << "You have chosen the letter " << gameGuess << … | |
Re: [QUOTE=pltndragon;922048] Why doesn't it calculate the average properly, or how do you get it to calculate the average without changing using the lowest grade in the calculation. Thanks. [/QUOTE] [CODE=cplusplus] //Get lowest lowest = scores[0]; //Without the for loop code works fine. //for ( int count = 1; count < … | |
Re: cin>>passage; cin would stop reading as soon as it encounters a space ! Use getline instead: getline (cin , passage) while(letter!='\n') { cin.get(letter); while(letter=" "); //<<extra character makes it redundant;) //while(isspace(cin.peek())&&letter=='\n') { cin.get(letter); cout<<"the letter is"<<letter; space++; } } Instead , for (int i = 0 ; i < passage.length() … | |
Re: The series breaks down to:: 1 - 2 / (2 *1) +3 / (3*2!) -.... i.e 1 - 1 + 1/2! - 1/3! So the first (major) 2 terms of the series cancel out. Now, may be you define a variable [CODE]int sign_carrier = 1 ; long fact = 1; … | |
Re: Since you are just finding the prime factors of a number,how about something like this:: [CODE=c++] //fragment code where num is your real number if(num>0) { for(int i=1;i<=num;++i) { if(i==1) { cout<<i<<" ";//Can be done without it continue;//Don't dare get into a while loop with 1 } while(num%i==0) { cout<<i<<" … | |
Re: [QUOTE] ..problem is after the program works the first time, then the user wants to do it again( which I use a while loop) , for example , choose row 1 B, the form will show X at row 1 B, but not the row 2 A ( which the … | |
Re: I think in the function [CODE] void displayInstructions () //You should be passing //these parameters by reference //float initial, fuel, taxRate; //since you seem to use those values in // float totalHouseCost (float initial, float fuel, float taxRate) //and in float totalHouseCost (float initial, float fuel, float taxRate) //you must … | |
Re: [QUOTE] [CODE=c] for(c=0;c<5;c++) { if(d==no[c]) loc=loc+1;<<< change it to loc=i; //But where is i,the control variable is c //Should be loc=c [/CODE] [/QUOTE] This would certainly work if all the numbers are distinct,else you 'll get only the last occurrence of that number in the 'loc' | |
Re: [QUOTE=siddhant3s] [CODE] for(int i;i<len-1;i++)//No initialization of i //you surely meant //for(int i=0; i<len ;i++) { if(str[i]=' ')//is this right?? and what if last character is a space. . . [/CODE] [/QUOTE] Instead use strings. | |
Re: First,for a a number in an array call it as [CODE] int num;[/CODE] [CODE=c] //Your expression for evaluating control variable //certainly doesn't give all the factors,referring to //for (int j = 2; j <= floor (sqrt((double)integerIn)); j++) //try for integerIn=999; //999's square root lying between 31 and 32 while one … | |
Re: [QUOTE] converts lower case letters to upper case letters. . . not display strange characters [/QUOTE] You were displaying all the letters [CODE=c] for (loopCount= 0;loopCount < numLetters;loopCount++) { //to display CAPITAL letters //You enter inside if block only if it is a small letter. //else you don't display the … | |
Re: [QUOTE] capacity: 10 seats [/QUOTE] [QUOTE] [CODE] int seat[40]={0}; /*What for?*/ [/CODE] [/QUOTE] You don't loop through your statements to see whether [I] both the choices work for you [/I] [CODE] if (choice =2) [/CODE] If suppose I have booked a ticket,have you placed a 1 in the index position … | |
Re: You almost got it right . [CODE=c++] char name[5][50]; for(int i=0;i<5;i++) { cin.getline(name[i], 50); } for(int i=0;i<5;i++) { //or cout<<name[i]<<"\n"; cout<<**(name+i)<<endl; } [/CODE] [CODE]*name[i][/CODE] is equivalent to [CODE]**(name+i)[/CODE] which displays only the first character of the line entered. Also you don't require a buffer as [CODE]cin.getline(...)[/CODE] automatically appends a '\0' … | |
Re: Though ,not a good approach but the following approach does work.(if your input contains texts which are separated by more than a couple of newlines,expect some unexpected characters in the output) Inside the while loop [CODE] while (getline(filename, line)) //Loop through lines { char str[BUFSIZ] ;//BUFSIZ // already defined in … | |
Re: [QUOTE=nitu_thakkar;779631]suppose i want to do shift left operation on x=1010 y=x<<1 it will shift left the value & make x=0100 but how can i store that shifted value... in other variable...? please help me to solve this query[/QUOTE] 1. l x=10; and left shifting the bits once does not give … |