Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
P

planetx22

@planetx22
About
Posts
12
Topics
4
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Output correct value
    P planetx22

    This is the output I get from my program now, but after it ouputs the correct value it says outputs another number like -12323e.6 and then says "Program Complete!" again. How do i get rid of this second output? Im also getting an error message - line [14] conversion from double to float, possible loss of data. Thanks.

    // Computer Lab test.cpp : Program that asks for temperature inputs,
    // ensures input is in centigrade, and outputs # of arrays + corrected temp

    // Andrew Stewart CMPT 201

    #include "stdafx.h"
    #include using namespace std;

    float CheckCent(float c) // Function to convert user values into centigrade(celsius) <- function named CheckCent
    {
    if(c>30)
    {
    c=(c-32)/(1.80); return c; // formula for fahrenheit to celsius(centigrade)
    }
    else return c;
    }
    int _tmain(int argc, _TCHAR* argv[]) // Main function
    {
    float myarray[50]; // declare array from 0-49 values
    int flag; // counter for loop
    flag=1;
    int i; // number of arrays
    for(i = 0; i < 50 && flag == 1; i++)
    {
    cout << "Enter Temperature Reading:";
    cin >>myarray[i];
    cout << "Enter 1 to input more values, 0 to stop";
    cin >>flag;
    }// End for
    cout << "\n\nNumber of elements in the array is: " << i <

    C / C++ / MFC c++ data-structures

  • Output correct value
    P planetx22

    My program works fine if the temperature entered is above 30(say 100).. it will perform the calculations and output the result. I need it to also output the number if it is below 30 (if i enter 29, it outputs 29) but i can't get it to output anything. Thnx for the advice.

    // Computer Lab test.cpp : Program that asks for temperature inputs,
    // ensures input is in centigrade, and outputs # of arrays + corrected temp

    // Andrew Stewart CMPT 201

    #include "stdafx.h"
    #include using namespace std;

    float CheckCent(float c) // Function to convert user values into centigrade(celsius) <- function named CheckCent
    {
    if (c > 30.0)
    {
    c=(c-32.0)/(1.80); return c; // formula for fahrenheit to celsius(centigrade)
    }
    return c;
    }
    int _tmain(int argc, _TCHAR* argv[]) // Main function
    {
    float myarray[50]; // declare array from 0-49 values
    int flag; // counter for loop
    flag=1;
    int i; // number of arrays
    for(i = 0; i < 50 && flag == 1; i++)
    {
    cout << "Enter Temperature Reading:";
    cin >>myarray[i];
    cout << "Enter 1 to input more values, 0 to stop";
    cin >>flag;
    }// End for
    cout << "\n\nNumber of elements in the array is: " << i <30.0)
    {
    myarray[j]=CheckCent(myarray[j]);
    cout <<"The corrected value is: ";
    cout <

    C / C++ / MFC c++ data-structures

  • Function help [modified]
    P planetx22

    Is this better? I kinda figured out how to use the function, but now I think thats where my problem lies. When i choose say 35 as the first value inputted, and then stop the loop, i dont get a correct celsius value but a number like 14.2323.2323. Here is my updated code, thanks. [code] // Computer Lab test.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include using namespace std; // call this function to convert fahrenheit values into celsius (function name is CheckCent) double CheckCent(double c) { if (c <= 30) return c; c=c-32/1.8; return c; } // main function int _tmain(int argc, _TCHAR* argv[]) { double myarray[51]; //double i; int flag; flag=1; int i; for(i = 0; i < 51 && flag == 1; i++) { // Loop to enter temperatures - pressing 1 continues, pressing 0 stops // cout << "Enter Temperature Reading:"; cin >>myarray[i]; cout << "Enter 1 to input more values, 0 to stop"; cin >>flag; }// End for cout << "Number of elements in the array is: " << i; cout <<"\n"; for(int j=0;j<=i;j++) { myarray[j]=CheckCent(myarray[j]); cout << myarray[0]; } return 0; } [/code]

    C / C++ / MFC question c++ data-structures help tutorial

  • Function help [modified]
    P planetx22

    updated code again, I think my function isn't working because when i return the value it doesnt look like its changed to celsius. Also, i only know how to print the value of myarray[0], how do i print each value entered? Thanks for the help. Code: // Computer Lab test.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include using namespace std; double c; double CheckCent(double c) { if (c>30) { return c - 32 /1.8; } return c; } // call this function to convert fahrenheit values into celsius (function name is CheckCent) int _tmain(int argc, _TCHAR* argv[]) { double myarray[51]; //double i; int flag; flag=1; int i; for(i = 0; i < 51 && flag == 1; i++) { // Loop to enter temperatures - pressing 1 continues, pressing 0 stops // cout << "Enter Temperature Reading:"; cin >>myarray[i]; cout << "Enter 1 to input more values, 0 to stop"; cin >>flag; }// End for cout << "Number of elements in the array is: " << i; while(i < 50) { myarray[i]=CheckCent(myarray[i]); cout <<"\n"; cout << myarray[0]; return 0; } }

    C / C++ / MFC question c++ data-structures help tutorial

  • Still need a bit of help please
    P planetx22

    thanks alot.. got me on the right track i think. My function goes like - double my func(double fahrenheit) { if (fahrenheit>100) fahrenheit = 1.8 * celsius + 32; return fahrenheit; }; Im just not sure how to make the value the user enters into myarray[0-50] go into fahrenheit and then do the check, then return the value to the array either fixed with the formula or not because it was not greater than 100. Can I do something like in my for loop before the user chooses to continue or stop, or is that the wrong spot? And would it be something like - myarray[i]=my func(myarray[i]; ? Thanks alot for the help.

    C / C++ / MFC help question c++ data-structures

  • Still need a bit of help please
    P planetx22

    Ahh.. of course I don't know why I didnt see that before thank you very much. The next thing I need to do is use a function i previously made to convert the values entered in array from fahrenheit (if they are) to celsius. Im just not sure how to make the computer know if the values entered are fahrenheit or not (i know the math formula, just not how to use it). Any help much appreciated thanks.

    C / C++ / MFC help question c++ data-structures

  • Still need a bit of help please
    P planetx22

    Ok, so thanks to the help I have the program working somewhat correctly, I think. It has 2 loops, a for and while.. one allows the user to keep inputting data into an array that will be defined by the user in size but is no more than 50 values. I have a while loop in this that will ask user to input 1 to continue, 0 to stop entering temperatures. My problem is, I think the values are being stored correctly cause when i choose to output say myarray[0] the correct value I input comes up, but I want to be able to print out how many actual arrays there are in a statement like "Number of readings entered is 12," not the values in them (although I hope i stored each one properly). This is where I am stuck. From here I have to take the data and make sure its all in centigrade. Im pretty sure I can write a basic function to do this part, but how do I make a statement to call this in my loop as the user inputs functions, and then prints out how many there are? Any help much appreciated thanks. // Computer Lab test.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include using namespace std; int _tmain(int argc, _TCHAR* argv[]) { double myarray[51]; int i; int flag; flag=1; for(i= 0; i < 50; i++) while (flag==1) { // loop to enter temperatures - pressing 1 continues, pressing 0 stops // cout << "Enter Temperature Reading:"; cin >>myarray[i]; cout << "Enter 1 to input more values, 0 to stop"; cin >>flag; } std::cout << myarray[i] << std::endl; return 0; }

    C / C++ / MFC help question c++ data-structures

  • Array Help Please (user defined size)
    P planetx22

    haven't covered that much so we didn't have it mentioned as part of the project. I will look into them and post if I have any problems, thanks.

    C / C++ / MFC c++ data-structures help tutorial

  • Array Help Please (user defined size)
    P planetx22

    ok thank you. If i do use this and user myarray[i] as the user input, will this put data into 0-49 of the array , or until the user wants to stop?

    C / C++ / MFC c++ data-structures help tutorial

  • Array Help Please (user defined size)
    P planetx22

    if i make another variable, say i.. and define it like int i i=0 (not sure if this is right) for i=0, i<50, i++ { // cout "Enter Temperatures"; cin >> myarray[i] does that work better?

    C / C++ / MFC c++ data-structures help tutorial

  • Array Help Please (user defined size)
    P planetx22

    No problem, I understand and I hope I can learn through my errors. So far my program I think stores a temporary function at the start that converts any value of number entered into a double fahrenheit and returns it to another double celsius. I stored that there just for formula's sake, and haven't implemented it or really know how to use it yet. Then i think in this part I have correctly made an array of 50 doubles called myarray. Then i have made an int value flag that is in place of if the user puts a 1 or 0 to continue/stop the program. I want to be able to make an array that is assumed to be less than 50 values, and then the user to keep entering values until done, but I think I have it setup wrong is it just storing the values inputted into myarray[50] only? Do I have to seperatly do myarray[0], myarray[1], etc each time or is there some other loop i can make that can tell the program to keep entering values starting from [0] until when the user wants to stop. Then it should print out how many arrays there are rather than values in them. I just can't figure out how to stop the array and have the values only how many the user inputed, not all 50. Any help greatly appreciated thanks. // Computer Lab test.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include using namespace std; // call this function to convert celsius to fahrenheit (function name is convert) double convert(double celsius){ double fahrenheit = ((9.0/5.0) * celsius) + 32; return fahrenheit; }; int _tmain(int argc, _TCHAR* argv[]) { double myarray[50]; int flag; flag =1; while (flag==1) { // loop cout << "Enter Temperature Reading:"; cin >>myarray[50] ;cout << " Enter 1 to input more values, 0 to stop"; cin >>flag; } return 0; }

    C / C++ / MFC c++ data-structures help tutorial

  • Array Help Please (user defined size)
    P planetx22

    I have having a bit of trouble, i need to write a program that converts fahrenheit to celsius (i can do the function for this part) but it needs to start with a loop that first prompts the user to "Enter Temperature:" and then stores the value entered into the array which is supposed to be no more than 50. I am having issues with how to input data into the array starting at 0 and keep going up 1 (all I can do is input data directly to myarray[50], but I want the user to input data and it be entered into the array like enter data one > put in array[0] enter data 2 > put in array[1] The program also has to ask the user if they want to keep entering data by pressing 1, or stop by pressing 0. The program then has to display how many arrays there are of temperatures (not the value of them, just how many there are). Please help!! This is what I have so far, any help greatly appreciated. // Computer Lab test.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include using namespace std; // call this function to convert celsius to fahrenheit (function name is convert) double convert(double celsius){ double fahrenheit = ((9.0/5.0) * celsius) + 32; return fahrenheit; }; int _tmain(int argc, _TCHAR* argv[]) { double myarray[50]; int flag; flag =1; while (flag==1) { // loop cout << "Enter Temperature Reading:"; cin >>myarray[50] ;cout << " Enter 1 to input more values, 0 to stop"; cin >>flag; } return 0; }

    C / C++ / MFC c++ data-structures help tutorial
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups