program help

Pages: 12
Mar 3, 2017 at 6:11pm
know how to fix



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Example program
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int ages [15] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,};
int sum, result=0;
int average;
std::string shoe;

int main()
{
  std::string name;
  std::cout << "What is your name? ";
  getline (std::cin, name);
  std::cout << "Hello, " << name << "!\n";
  
  std::cout << "how are you doing today? ";
  getline (std::cin, name);
  std::cout << "that's good" << "\n";
  
  std::cout << "what do you like to do for fun?";
  getline (std::cin, name);
  std::cout << " cool i like to play video games" << "\n";
  
std::string age;
std::cout << "how old are you";
std::cin >> age;
std::cout<<"wow your older than me""\n";

getline (std::cin, name);
std::cout<<"what is your favorite video game?" "\n";
getline (std::cin, name);
std::cout<<"that game is fun but my favorite is cod" "\n";

  std::cout<<"what is your shoe size";
    getline (std::cin, shoe);
    std:: cout<<" tell everyone else around you to input their shoe size if there isnt anyone else just input 0";    
    getline (std::cin, shoe);
    getline (std::cin, shoe);
    getline (std::cin, shoe);
    getline (std::cin, shoe);
    
  
    sum = (ages + shoe); // it says this is wrong and i dont know why there might be a mistake somewhere
    
    average =(sum/5);
    std::cout << result;
    return 0;
}


Last edited on Mar 3, 2017 at 7:35pm
Mar 3, 2017 at 6:12pm
im new to pragramming so i thought you guys could help me
Mar 3, 2017 at 7:17pm
Line 25,31: These are function prototypes. You don't need a function prototypes for main().

Line 46: You can't add an int array and a string.

Line 48: You're doing integer division. You're not going to get the result you expect.

Line 49: Where did result come from? It was initialized to 0 and never changed.

What are you trying to fix? Please be specific.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Last edited on Mar 3, 2017 at 7:26pm
Mar 3, 2017 at 7:22pm
ok i put in where the program says the problem is. sorry im new
Mar 3, 2017 at 7:30pm
See my previous comment about line 46. Why are you trying to add an int array and a string? What is this supposed to do?

Please edit your post and apply code tags per my previous request.
Mar 3, 2017 at 7:30pm
what do youmean by code tags
Mar 3, 2017 at 7:31pm
Read the link I provided. Code tags provide line numbering and syntax highlighting.
Mar 3, 2017 at 7:35pm
i think i did it your being pretty helpful so far thx but i still dont know whats wrong with the code
Last edited on Mar 3, 2017 at 7:37pm
Mar 3, 2017 at 8:07pm
but i still dont know whats wrong with the code

Line 45: I've pointed out twice that you can't add an int array (ages) to a string (shoe).

Please explain what you are trying to do with that line.
Last edited on Mar 3, 2017 at 8:09pm
Mar 3, 2017 at 8:17pm
im trying to make people put in their shoe sizes then it shoould output all of the shoe sizes added put together then divide them by five i need to chance that five to fifteen so dont pay attention to that but im probably doing that whole part of the program wrong so thats why i asked for help because i dont know exactly how to do what im wanting to do it should take the shoe sizes then add them together then display that then divide it by 15. and thats all i was wanting to do but idk how.
Mar 3, 2017 at 9:02pm
Something like this:
36
37
38
39
40
41
42
43
44
45
46
47
48
    int shoes[5];       // Allocate an array for shoe sizes
    cout << "What is your shoe size? ";
    cin >> shoes[0]; 
    cout<<"Tell four people around you to input their shoe size";    
    cin >> shoes[1]; 
    cin >> shoes[2]; 
    cin >> shoes[3]; 
    cin >> shoes[4]; 
    sum = 0;            //  Initialize sum
    for (int i=0; i<5;i++)
        sum += shoes[i];  
    average = (sum/5);  
    cout << "Average shoe size is: " << average << endl;

Mar 3, 2017 at 9:04pm
what does allocate mean
Mar 3, 2017 at 9:09pm
you are soo helpful thanks
Mar 3, 2017 at 9:14pm
Allocate means "reserve storage for".
Mar 3, 2017 at 9:16pm
ok i got it to work but how do i display all the shoe sizes they entered added together also along with the average
Mar 3, 2017 at 9:24pm
Simply iterate through the array and print each entry in the array.
1
2
3
  cout << "Shoe sizes are: " << endl;
  for (int i=0; i<5;i++)
      cout << shoes[i] << endl;
Mar 3, 2017 at 9:24pm
1
2
3
4
5
6
7
8
9
std::string age;
std::cout << "how old are you";
std::cin >> age;
if (age==13) // says this is wrong { 
    cout<< "you are the same age as me";}
    else if ( age > 13 )  // says this is wrong { 
        cout<< "you are older than me";}
     else if ( age < 13 ) // says this is wrong {
        cout<< "you are younger then me";}
Mar 3, 2017 at 9:26pm
any ideas on that one right there
because i have a code just like it and it works
Mar 3, 2017 at 9:35pm
Line 4,6,8: age is a string. You can't compare a string to an integer (13).

Change age to an int.

Mar 3, 2017 at 9:38pm
you are so helpful could you explain this code to me i dont know how it works
1
2
3
for (int i=0; i<5;i++)
        sum += shoes[i]; 
        cout << "Shoe sizes are: " << endl;
Pages: 12